{"record":{"id":"8a0fd930bf2068c8","repo":"micro/go-micro","slug":"message-passed-in-is-nil-8a0fd9","errorCode":null,"errorMessage":"message passed in is nil","messagePattern":"message passed in is nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"transport/http_socket.go","lineNumber":49,"sourceCode":"\n\t// local/remote ip\n\tlocal  string\n\tremote string\n\n\tmtx sync.RWMutex\n}\n\nfunc (h *httpTransportSocket) Local() string {\n\treturn h.local\n}\n\nfunc (h *httpTransportSocket) Remote() string {\n\treturn h.remote\n}\n\nfunc (h *httpTransportSocket) Recv(msg *Message) error {\n\tif msg == nil {\n\t\treturn errors.New(\"message passed in is nil\")\n\t}\n\n\tif msg.Header == nil {\n\t\tmsg.Header = make(map[string]string, len(h.r.Header))\n\t}\n\n\tif h.r.ProtoMajor == 1 {\n\t\treturn h.recvHTTP1(msg)\n\t}\n\n\treturn h.recvHTTP2(msg)\n}\n\nfunc (h *httpTransportSocket) Send(msg *Message) error {\n\t// we need to lock to protect the write\n\th.mtx.RLock()\n\tdefer h.mtx.RUnlock()\n","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/transport/http_socket.go#L31-L67","documentation":"httpTransportSocket.Rev — the server-side socket's Recv — requires the caller to supply a non-nil *Message into which the pending request's headers and body are decoded. A nil message leaves no destination for the data, so it returns 'message passed in is nil' without reading the socket.","triggerScenarios":"Server handler code calling sock.Recv(nil), or reusing a *Message variable left nil after a previous loop iteration/error.","commonSituations":"Handlers copied from client examples where the client allocates the message differently; error paths that set msg back to nil and continue looping on the socket.","solutions":["Initialize the message before each Recv: msg := &transport.Message{}; sock.Recv(msg)","Inside a receive loop, allocate a fresh message per iteration instead of reusing a possibly-nil variable","Wrap socket handling so a nil message can never be passed (small helper function that allocates then calls Recv)"],"exampleFix":"// before\nvar msg *transport.Message\nsock.Recv(msg) // error\n// after\nmsg := &transport.Message{}\nif err := sock.Recv(msg); err != nil { return err }","handlingStrategy":"validation","validationCode":"if msg == nil {\n\tmsg = &transport.Message{}\n}\nerr := sock.Recv(msg)","typeGuard":"func validMessage(m *transport.Message) bool { return m != nil }","tryCatchPattern":"if err := sock.Recv(msg); err != nil {\n\tif strings.Contains(err.Error(), \"message passed in is nil\") {\n\t\t// allocate a fresh message and continue the loop\n\t}\n}","preventionTips":["Allocate a fresh message inside every handler loop iteration","Wrap socket reads in a helper that guarantees non-nil messages","Don't reset msg to nil on error paths while continuing to Recv"],"tags":["transport","socket","nil-argument"],"backgroundTag":"nil-message-argument","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}