Skip to content

Fix: Handle peer KEEPALIVE messages in chaincode message handler#513

Merged
bestbeforetoday merged 1 commit into
hyperledger:mainfrom
dzikowski:fix/keepalive
May 31, 2026
Merged

Fix: Handle peer KEEPALIVE messages in chaincode message handler#513
bestbeforetoday merged 1 commit into
hyperledger:mainfrom
dzikowski:fix/keepalive

Conversation

@dzikowski
Copy link
Copy Markdown
Contributor

When Node.js chaincode receives keepalive message from the peer, it treats it as unknown message - it is not handled by Node.js chaincode shim. It produces the unknown message error and exits the chaincode process.

In such case the following logs are produced:

<date> debug [c-api:lib/handler.js] Received chat message from peer: , state: ready, type: 18
<date> error [c-api:lib/handler.js] Received unknown message from the peer. Exiting.

It turns out the Go shim handles keepalive message (source):

if msg.Type == peer.ChaincodeMessage_KEEPALIVE {
    h.serialSendAsync(msg, errc)
    return nil
}

This PR adds the same behavior to the node shim:

            if (msg.type === MSG_TYPE.KEEPALIVE) {
                stream.write(msgpb);
                return;
            }

@dzikowski dzikowski requested a review from a team as a code owner May 29, 2026 13:37
The Node.js shim exited when the peer sent KEEPALIVE (type 18) on idle
connections, which breaks long-running chaincode such as CCAAS. Echo
KEEPALIVE back to the peer and align behaviour with the Go chaincode
shim.

Signed-off-by: Jakub Dzikowski <jakub.t.dzikowski@gmail.com>
@bestbeforetoday
Copy link
Copy Markdown
Member

Thank you very much for this contribution and for including tests.

@bestbeforetoday bestbeforetoday merged commit d66fdc9 into hyperledger:main May 31, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants