From bd68a198cf56d26ec4760eebdc71ec0cf2395817 Mon Sep 17 00:00:00 2001 From: Danny Cao Date: Thu, 23 Apr 2020 16:17:21 -0400 Subject: [PATCH] [FAB-17728] Add 100ms delay to pkcs11 create session loop after failing to retrieve a session from the HSM session cache Signed-off-by: Danny Cao --- bccsp/pkcs11/pkcs11.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bccsp/pkcs11/pkcs11.go b/bccsp/pkcs11/pkcs11.go index 33fccb6b03c..f8f9dae485e 100644 --- a/bccsp/pkcs11/pkcs11.go +++ b/bccsp/pkcs11/pkcs11.go @@ -15,6 +15,7 @@ import ( "fmt" "math/big" "sync" + "time" "github.com/miekg/pkcs11" "go.uber.org/zap/zapcore" @@ -93,6 +94,7 @@ func (csp *impl) getSession() (session pkcs11.SessionHandle) { func createSession(ctx *pkcs11.Ctx, slot uint, pin string) pkcs11.SessionHandle { var s pkcs11.SessionHandle var err error + // attempt 10 times to open a session with a 100ms delay after each attempt for i := 0; i < 10; i++ { s, err = ctx.OpenSession(slot, pkcs11.CKF_SERIAL_SESSION|pkcs11.CKF_RW_SESSION) if err != nil { @@ -100,6 +102,7 @@ func createSession(ctx *pkcs11.Ctx, slot uint, pin string) pkcs11.SessionHandle } else { break } + time.Sleep(100 * time.Millisecond) } if err != nil { logger.Fatalf("OpenSession failed [%s]", err)