{"record":{"id":"18a62c542bfede3f","repo":"hyperledger/fabric","slug":"block-from-orderer-could-not-be-re-marshaled-prot","errorCode":null,"errorMessage":"block from orderer could not be re-marshaled: proto: Marshal called with nil","messagePattern":"block from orderer could not be re-marshaled: proto: Marshal called with nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/deliverservice/gossip_block_handler.go","lineNumber":37,"sourceCode":"//\n//go:generate counterfeiter -o fake/gossip_service_adapter.go --fake-name GossipServiceAdapter . GossipServiceAdapter\ntype GossipServiceAdapter interface {\n\t// AddPayload adds payload to the local state sync buffer\n\tAddPayload(chainID string, payload *gossip.Payload) error\n\n\t// Gossip the message across the peers\n\tGossip(msg *gossip.GossipMessage)\n}\n\ntype GossipBlockHandler struct {\n\tgossip              GossipServiceAdapter\n\tblockGossipDisabled bool\n\tlogger              *flogging.FabricLogger\n}\n\nfunc (h *GossipBlockHandler) HandleBlock(channelID string, block *common.Block) error {\n\tif block == nil {\n\t\treturn errors.New(\"block from orderer could not be re-marshaled: proto: Marshal called with nil\")\n\t}\n\tmarshaledBlock, err := proto.Marshal(block)\n\tif err != nil {\n\t\treturn errors.WithMessage(err, \"block from orderer could not be re-marshaled\")\n\t}\n\n\t// Create payload with a block received\n\tblockNum := block.GetHeader().GetNumber()\n\tpayload := &gossip.Payload{\n\t\tData:   marshaledBlock,\n\t\tSeqNum: blockNum,\n\t}\n\n\t// Use payload to create gossip message\n\tgossipMsg := &gossip.GossipMessage{\n\t\tNonce:   0,\n\t\tTag:     gossip.GossipMessage_CHAN_AND_ORG,\n\t\tChannel: []byte(channelID),","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/deliverservice/gossip_block_handler.go#L19-L55","documentation":"GossipBlockHandler.HandleBlock returns this fixed-message error when the block received from the orderer is nil, before attempting proto.Marshal. The message text mirrors the proto error that marshaling a nil message would produce ('proto: Marshal called with nil'), so callers can treat it uniformly. It signals the orderer/gossip path handed the handler an invalid block.","triggerScenarios":"HandleBlock(channelID, block) is invoked with block == nil, e.g. a nil block propagated from the deliver client or gossip pipeline.","commonSituations":"Orderer disconnects or upstream bugs yielding nil blocks; version mismatches between orderer and peer; corrupted internal state in the block delivery pipeline; tests invoking HandleBlock with nil to simulate bad input.","solutions":["Fix the upstream producer so it never invokes HandleBlock with a nil block; add a nil check before calling it","Log and drop the nil block on the caller side, resyncing blocks via the normal delivery stream","Upgrade orderer/peer to matching versions to rule out serialization bugs","If persistent, capture orderer logs and file an issue; restart the delivery service to re-establish the block stream"],"exampleFix":"// before\nhandler.HandleBlock(channelID, blockFromOrderer) // block may be nil\n// after\nif blockFromOrderer == nil {\n    logger.Warningf(\"skipping nil block for channel %s\", channelID)\n    return\n}\nhandler.HandleBlock(channelID, blockFromOrderer)","handlingStrategy":"type-guard","validationCode":"if block == nil || block.Header == nil {\n    logger.Warningf(\"invalid block from orderer for channel %s\", channelID)\n    return\n}\nHandleBlock(channelID, block)","typeGuard":"func isValidBlock(b *common.Block) bool {\n    return b != nil && b.Header != nil && b.Data != nil\n}","tryCatchPattern":"if err := handler.HandleBlock(channelID, blk); err != nil {\n    if strings.Contains(err.Error(), \"could not be re-marshaled\") {\n        logger.Errorf(\"dropping invalid block on %s: %v\", channelID, err)\n        return nil\n    }\n    return err\n}","preventionTips":["Nil-check blocks at every boundary in the gossip/delivery pipeline","Keep orderer and peer on compatible Fabric versions","Monitor delivery stream health to detect upstream nil/short reads early"],"tags":["protobuf","nil-value","gossip","hyperledger-fabric"],"backgroundTag":"nil-block","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}