Skip to content

Commit

Permalink
[FAB-17728] Add 100ms delay to pkcs11 create session loop
Browse files Browse the repository at this point in the history
after failing to retrieve a session from the HSM session cache

Signed-off-by: Danny Cao <dcao@us.ibm.com>
  • Loading branch information
caod123 authored and sykesm committed Apr 23, 2020
1 parent 4c10bce commit bd68a19
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bccsp/pkcs11/pkcs11.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"fmt"
"math/big"
"sync"
"time"

"github.com/miekg/pkcs11"
"go.uber.org/zap/zapcore"
Expand Down Expand Up @@ -93,13 +94,15 @@ 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 {
logger.Warningf("OpenSession failed, retrying [%s]\n", err)
} else {
break
}
time.Sleep(100 * time.Millisecond)
}
if err != nil {
logger.Fatalf("OpenSession failed [%s]", err)
Expand Down

0 comments on commit bd68a19

Please sign in to comment.