Skip to content

Commit

Permalink
Merge pull request #89 from kaleido-io/mutex-unlock
Browse files Browse the repository at this point in the history
Use defer to unlock mutex
  • Loading branch information
peterbroadhurst authored Jun 2, 2022
2 parents 202008b + 22d8b9f commit 4f6ff0c
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/fabric/client/client_ccp.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func (w *ccpRPCWrapper) SignerUpdated(signer string) {

func (w *ccpRPCWrapper) getChannelClient(channelId string, signer string) (*ccpClientWrapper, error) {
w.mu.Lock()
defer w.mu.Unlock()
id, err := w.idClient.GetSigningIdentity(signer)
if err == msp.ErrUserNotFound {
return nil, errors.Errorf("Signer %s does not exist", signer)
Expand Down Expand Up @@ -169,7 +170,6 @@ func (w *ccpRPCWrapper) getChannelClient(channelId string, signer string) (*ccpC
w.channelClients[channelId][id.Identifier().ID] = newWrapper
clientOfUser = newWrapper
}
w.mu.Unlock()
return clientOfUser, nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/fabric/client/client_gateway_clientside.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func (w *gwRPCWrapper) sendTransaction(signer, channelId, chaincodeName, method
// the discovery service and selecting the right set of endorsers are automated
func (w *gwRPCWrapper) getGatewayClient(channelId, signer string) (gatewayClient *gateway.Network, err error) {
w.mu.Lock()
defer w.mu.Unlock()
gatewayClientsForSigner := w.gwGatewayClients[signer]
if gatewayClientsForSigner == nil {
// no channel clients have been created for this signer at all
Expand All @@ -200,7 +201,6 @@ func (w *gwRPCWrapper) getGatewayClient(channelId, signer string) (gatewayClient
}
gatewayClientsForSigner[channelId] = gatewayClient
}
w.mu.Unlock()
return gatewayClient, nil
}

Expand All @@ -209,6 +209,7 @@ func (w *gwRPCWrapper) getGatewayClient(channelId, signer string) (gatewayClient
// do a "strong read" across multiple peers
func (w *gwRPCWrapper) getChannelClient(channelId, signer string) (channelClient *channel.Client, err error) {
w.mu.Lock()
defer w.mu.Unlock()
channelClientsForSigner := w.gwChannelClients[signer]
if channelClientsForSigner == nil {
channelClientsForSigner = make(map[string]*channel.Client)
Expand All @@ -230,7 +231,6 @@ func (w *gwRPCWrapper) getChannelClient(channelId, signer string) (channelClient
}
channelClientsForSigner[channelId] = channelClient
}
w.mu.Unlock()
return channelClient, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/fabric/client/eventsubscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func (e *eventClientWrapper) subscribeEvent(subInfo *eventsapi.SubscriptionInfo,

func (e *eventClientWrapper) getEventClient(channelId, signer string, since uint64, chaincodeId string) (eventClient *event.Client, err error) {
e.mu.Lock()
defer e.mu.Unlock()
eventClientsForSigner := e.eventClients[signer]
if eventClientsForSigner == nil {
eventClientsForSigner = make(map[string]*event.Client)
Expand All @@ -120,7 +121,6 @@ func (e *eventClientWrapper) getEventClient(channelId, signer string, since uint
}
eventClientsForSigner[key] = eventClient
}
e.mu.Unlock()
return eventClient, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/fabric/client/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func (l *ledgerClientWrapper) queryTransaction(channelId, signer, txId string) (

func (l *ledgerClientWrapper) getLedgerClient(channelId, signer string) (ledgerClient *ledger.Client, err error) {
l.mu.Lock()
defer l.mu.Unlock()
ledgerClientsForSigner := l.ledgerClients[signer]
if ledgerClientsForSigner == nil {
ledgerClientsForSigner = make(map[string]*ledger.Client)
Expand All @@ -134,7 +135,6 @@ func (l *ledgerClientWrapper) getLedgerClient(channelId, signer string) (ledgerC
}
ledgerClientsForSigner[channelId] = ledgerClient
}
l.mu.Unlock()
return ledgerClient, nil
}

Expand Down

0 comments on commit 4f6ff0c

Please sign in to comment.