Skip to content

Commit

Permalink
FABJ-452 shutdown spurious NPE
Browse files Browse the repository at this point in the history
Calling Channel.shutdown() can cause spurious NullPointerExceptions

Change-Id: Ie28a425eed31299fa6441fe8aedecf15e7407d54
Signed-off-by: rickr <[email protected]>
  • Loading branch information
cr22rc committed Jun 19, 2019
1 parent db22412 commit 5e25c68
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
19 changes: 11 additions & 8 deletions src/main/java/org/hyperledger/fabric/sdk/Peer.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,7 @@ void initiateEventing(TransactionContext transactionContext, PeerOptions peersOp

this.transactionContext = transactionContext.retryTransactionSameContext();

if (peerEventingClient == null) {

//PeerEventServiceClient(Peer peer, ManagedChannelBuilder<?> channelBuilder, Properties properties)
// peerEventingClient = new PeerEventServiceClient(this, new HashSet<Channel>(Arrays.asList(new Channel[] {channel})));
if (peerEventingClient == null && !shutdown) {

peerEventingClient = new PeerEventServiceClient(this, Endpoint.createEndpoint(url, properties), properties, peersOptions);

Expand All @@ -169,6 +166,10 @@ Channel getChannel() {

}

boolean isShutdown() {
return shutdown;
}

/**
* Set the channel the peer is on.
*
Expand Down Expand Up @@ -434,10 +435,12 @@ public void reconnect(Long startBLockNumber) throws TransactionException {
peerOptions.startEvents(startBLockNumber);
}

PeerEventServiceClient lpeerEventingClient = new PeerEventServiceClient(Peer.this,
Endpoint.createEndpoint(url, properties), properties, peerOptions);
lpeerEventingClient.connect(fltransactionContext);
peerEventingClient = lpeerEventingClient;
if (!shutdown) {
PeerEventServiceClient lpeerEventingClient = new PeerEventServiceClient(Peer.this,
Endpoint.createEndpoint(url, properties), properties, peerOptions);
lpeerEventingClient.connect(fltransactionContext);
peerEventingClient = lpeerEventingClient;
}

}
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ class PeerEventServiceClient {
private static final long PEER_EVENT_REGISTRATION_WAIT_TIME = config.getPeerEventRegistrationWaitTime();
private static final long PEER_EVENT_RECONNECTION_WARNING_RATE = config.getPeerEventReconnectionWarningRate();
private static final Log logger = LogFactory.getLog(PeerEventServiceClient.class);
private final String channelName;
private String channelName = null;
private final ManagedChannelBuilder channelBuilder;
private final String name;
private final String url;
private final long peerEventRegistrationWaitTimeMilliSecs;
private long peerEventRegistrationWaitTimeMilliSecs = PEER_EVENT_REGISTRATION_WAIT_TIME;

private final PeerOptions peerOptions;
private final boolean filterBlock;
Expand All @@ -79,14 +79,30 @@ class PeerEventServiceClient {
this.channelBuilder = endpoint.getChannelBuilder();
this.filterBlock = peerOptions.isRegisterEventsForFilteredBlocks();
this.peer = peer;
this.peerOptions = peerOptions;
name = peer.getName();
url = peer.getUrl();
channelName = peer.getChannel().getName();

if (peer.isShutdown()) {
logger.debug("PeerEventServiceClient not starting peer has shutdown.");
shutdown = true;
toString = "PeerEventServiceClient{" + "id: " + config.getNextID() + ", channel: null" + ", peerName: " + name + ", url: " + url + "}";
return;
}
final Channel channel = peer.getChannel();
if (channel == null) {
logger.debug("Peer no longer associated with a channel not connecting.");
shutdown = true;
toString = "PeerEventServiceClient{" + "id: " + config.getNextID() + ", channel: null" + ", peerName: " + name + ", url: " + url + "}";
return;
}

channelName = channel.getName();
toString = "PeerEventServiceClient{" + "id: " + config.getNextID() + ", channel: " + channelName + ", peerName: " + name + ", url: " + url + "}";
this.peerOptions = peerOptions;

clientTLSCertificateDigest = endpoint.getClientTLSCertificateDigest();

this.channelEventQue = peer.getChannel().getChannelEventQue();
this.channelEventQue = channel.getChannelEventQue();

if (null == properties) {

Expand Down Expand Up @@ -379,8 +395,12 @@ void connect(TransactionContext transactionContext) throws TransactionException

//=========================================================
// Peer eventing
void peerVent(TransactionContext transactionContext) throws TransactionException {
private void peerVent(TransactionContext transactionContext) throws TransactionException {
logger.trace(toString() + "peerVent transaction: " + transactionContext);
if (shutdown) { // check aagin
logger.debug("peerVent not starting, shutting down.");
return;
}

final Envelope envelope;
try {
Expand Down

0 comments on commit 5e25c68

Please sign in to comment.