@@ -341,10 +341,10 @@ func (c *Client) Connect(req ConnectRequest) {
341341 _ = c .unidirectionalConnect (req .toProto (), 0 , true )
342342}
343343
344- // ConnectNoDisconnect is the same as Client.Connect but does not try to extract Disconnect
345- // code from the error returned by the connect logic, instead it just returns the error
346- // to the caller. This error must be handled by the caller on the Transport level.
347- func (c * Client ) ConnectNoDisconnect (req ConnectRequest ) error {
344+ // ConnectNoErrorToDisconnect is the same as Client.Connect but does not try to extract
345+ // Disconnect code from the error returned by the connect logic, instead it just returns
346+ // the error to the caller. This error must be handled by the caller on the Transport level.
347+ func (c * Client ) ConnectNoErrorToDisconnect (req ConnectRequest ) error {
348348 return c .unidirectionalConnect (req .toProto (), 0 , false )
349349}
350350
@@ -394,33 +394,27 @@ func (c *Client) unidirectionalConnect(connectRequest *protocol.ConnectRequest,
394394 cmd = & protocol.Command {Id : 1 , Connect : connectRequest }
395395 err := c .issueCommandReadEvent (cmd , connectCmdSize )
396396 if err != nil {
397+ if c .node .clientEvents .commandProcessedHandler != nil {
398+ c .handleCommandFinished (cmd , protocol .FrameTypeConnect , err , nil , started )
399+ }
397400 if errorToDisconnect {
398401 d := extractUnidirectionalDisconnect (err )
399- if c .node .clientEvents .commandProcessedHandler != nil {
400- c .handleCommandFinished (cmd , protocol .FrameTypeConnect , & d , nil , started )
401- }
402402 go func () { _ = c .close (d ) }()
403403 return nil
404404 }
405- if c .node .clientEvents .commandProcessedHandler != nil {
406- c .handleCommandFinished (cmd , protocol .FrameTypeConnect , & DisconnectConnectionClosed , nil , started )
407- }
408405 return err
409406 }
410407 }
411408 _ , err := c .connectCmd (connectRequest , nil , time.Time {}, nil )
412409 if err != nil {
410+ if c .node .clientEvents .commandProcessedHandler != nil {
411+ c .handleCommandFinished (cmd , protocol .FrameTypeConnect , err , nil , started )
412+ }
413413 if errorToDisconnect {
414414 d := extractUnidirectionalDisconnect (err )
415- if c .node .clientEvents .commandProcessedHandler != nil {
416- c .handleCommandFinished (cmd , protocol .FrameTypeConnect , & d , nil , started )
417- }
418415 go func () { _ = c .close (d ) }()
419416 return nil
420417 }
421- if c .node .clientEvents .commandProcessedHandler != nil {
422- c .handleCommandFinished (cmd , protocol .FrameTypeConnect , & DisconnectConnectionClosed , nil , started )
423- }
424418 return err
425419 }
426420 if c .node .clientEvents .commandProcessedHandler != nil {
@@ -1134,12 +1128,12 @@ func isPong(cmd *protocol.Command) bool {
11341128 return cmd .Id == 0 && cmd .Send == nil
11351129}
11361130
1137- func (c * Client ) handleCommandFinished (cmd * protocol.Command , frameType protocol.FrameType , disconnect * Disconnect , reply * protocol.Reply , started time.Time ) {
1131+ func (c * Client ) handleCommandFinished (cmd * protocol.Command , frameType protocol.FrameType , err error , reply * protocol.Reply , started time.Time ) {
11381132 defer func () {
11391133 c .node .metrics .observeCommandDuration (frameType , time .Since (started ))
11401134 }()
11411135 if c .node .clientEvents .commandProcessedHandler != nil {
1142- event := newCommandProcessedEvent (cmd , disconnect , reply , started )
1136+ event := newCommandProcessedEvent (cmd , err , reply , started )
11431137 c .issueCommandProcessedEvent (event )
11441138 }
11451139}
@@ -1151,13 +1145,13 @@ func (c *Client) handleCommandDispatchError(ch string, cmd *protocol.Command, fr
11511145 switch t := err .(type ) {
11521146 case * Disconnect :
11531147 if c .node .clientEvents .commandProcessedHandler != nil {
1154- event := newCommandProcessedEvent (cmd , t , nil , started )
1148+ event := newCommandProcessedEvent (cmd , err , nil , started )
11551149 c .issueCommandProcessedEvent (event )
11561150 }
11571151 return t , false
11581152 case Disconnect :
11591153 if c .node .clientEvents .commandProcessedHandler != nil {
1160- event := newCommandProcessedEvent (cmd , & t , nil , started )
1154+ event := newCommandProcessedEvent (cmd , err , nil , started )
11611155 c .issueCommandProcessedEvent (event )
11621156 }
11631157 return & t , false
@@ -1170,7 +1164,7 @@ func (c *Client) handleCommandDispatchError(ch string, cmd *protocol.Command, fr
11701164 errorReply := & protocol.Reply {Error : toClientErr (err ).toProto ()}
11711165 c .writeError (ch , frameType , cmd , errorReply , nil )
11721166 if c .node .clientEvents .commandProcessedHandler != nil {
1173- event := newCommandProcessedEvent (cmd , nil , errorReply , started )
1167+ event := newCommandProcessedEvent (cmd , err , errorReply , started )
11741168 c .issueCommandProcessedEvent (event )
11751169 }
11761170 return nil , cmd .Connect == nil
0 commit comments