{"record":{"id":"0ddb414c6a938c09","repo":"shadow1ng/fscan","slug":"mcs-sendconnectinitial-write-error-v","errorCode":null,"errorMessage":"mcs sendConnectInitial write error %v","messagePattern":"mcs sendConnectInitial write error (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"libs/grdp/protocol/t125/mcs.go","lineNumber":303,"sourceCode":"\tglog.Debugf(\"clientNetworkData:%+v\", c.clientNetworkData)\n\tglog.Debugf(\"clientSecurityData:%+v\", c.clientSecurityData)\n\t// sendConnectclientCoreDataInitial\n\tuserDataBuff := bytes.Buffer{}\n\tuserDataBuff.Write(c.clientCoreData.Pack())\n\tuserDataBuff.Write(c.clientNetworkData.Pack())\n\tuserDataBuff.Write(c.clientSecurityData.Pack())\n\n\tccReq := gcc.MakeConferenceCreateRequest(userDataBuff.Bytes())\n\tconnectInitial := NewConnectInitial(ccReq)\n\tconnectInitialBerEncoded := connectInitial.BER()\n\n\tdataBuff := &bytes.Buffer{}\n\tber.WriteApplicationTag(uint8(MCS_TYPE_CONNECT_INITIAL), len(connectInitialBerEncoded), dataBuff)\n\tdataBuff.Write(connectInitialBerEncoded)\n\n\t_, err := c.transport.Write(dataBuff.Bytes())\n\tif err != nil {\n\t\tc.Emit(\"error\", errors.New(fmt.Sprintf(\"mcs sendConnectInitial write error %v\", err)))\n\t\treturn\n\t}\n\tglog.Debug(\"mcs wait for data event\")\n\tc.transport.Once(\"data\", c.recvConnectResponse)\n}\n\nfunc (c *MCSClient) recvConnectResponse(s []byte) {\n\tglog.Debug(\"mcs recvConnectResponse\", hex.EncodeToString(s))\n\tcResp, err := ReadConnectResponse(bytes.NewReader(s))\n\tif err != nil {\n\t\tc.Emit(\"error\", errors.New(fmt.Sprintf(\"ReadConnectResponse %v\", err)))\n\t\treturn\n\t}\n\t// record server gcc block\n\tserverSettings := gcc.ReadConferenceCreateResponse(cResp.userData)\n\tfor _, v := range serverSettings {\n\t\tswitch v.(type) {\n\t\tcase *gcc.ServerSecurityData:","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/libs/grdp/protocol/t125/mcs.go#L285-L321","documentation":"In MCSClient.connect, after building and BER-encoding the MCS Connect Initial PDU (carrying GCC client data), it is written to the transport. If transport.Write fails, the error is wrapped as 'mcs sendConnectInitial write error %v' and emitted on the 'error' channel. It is a low-level socket write failure during the MCS handshake.","triggerScenarios":"The call c.transport.Write(dataBuff.Bytes()) inside connect (invoked on the transport 'connect' event) returns a non-nil error — connection already closed, reset by peer, or the underlying socket is dead.","commonSituations":"Server closed the TCP connection immediately after TLS/security negotiation (e.g. NLA required but not supported); firewall or NAT drops the connection mid-handshake; network timeout; server crashed between connect and MCS phase.","solutions":["Inspect the wrapped inner error (%v) to identify the underlying cause (ECONNRESET, broken pipe, timeout).","Verify the server does not require NLA/CredSSP; if it does, the connection is typically torn down at this stage.","Retry the connection; transient network drops are common on WAN links.","Check TLS layer succeeded — a failed TLS handshake often leaves the transport unusable before this write."],"exampleFix":"// before\n_, err := c.transport.Write(dataBuff.Bytes())\nif err != nil {\n    c.Emit(\"error\", errors.New(fmt.Sprintf(\"mcs sendConnectInitial write error %v\", err)))\n    return\n}\n// after\n_, err := c.transport.Write(dataBuff.Bytes())\nif err != nil {\n    c.Emit(\"error\", fmt.Errorf(\"mcs sendConnectInitial write error: %w\", err))\n    c.transport.Close()\n    return\n}","handlingStrategy":"retry","validationCode":"// Check the transport is still alive before writing:\nif c.transport == nil {\n    return errors.New(\"transport not connected\")\n}","typeGuard":null,"tryCatchPattern":"mcs.On(\"error\", func(err error) {\n    if strings.Contains(err.Error(), \"sendConnectInitial write error\") {\n        // retry with backoff; surface the wrapped net error to the user\n    }\n})","preventionTips":["Confirm the TCP connection and TLS handshake succeeded before the MCS phase.","Verify the server does not require NLA and drop the connection early.","Use keepalives and connect-timeout settings appropriate to the network path."],"tags":["rdp","network","socket-write","mcs-handshake"],"backgroundTag":"broken-pipe","analyzedSha":"95cc12e753bf43de7004e5aef42a9ffba3934303","analyzedAt":"2026-09-06T17:07:30.094Z","contentChangedAt":"2026-09-06T17:07:30.094Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}