-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timeout all Identify stream reads #1032
Conversation
p2p/protocol/identify/id_push.go
Outdated
ids.handleIdentifyResponse(s) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^^
p2p/protocol/identify/id_push.go
Outdated
@@ -13,5 +14,7 @@ const IDPush = "/ipfs/id/push/1.0.0" | |||
|
|||
// pushHandler handles incoming identify push streams. The behaviour is identical to the ordinary identify protocol. | |||
func (ids *IDService) pushHandler(s network.Stream) { | |||
s.SetReadDeadline(time.Now().Add(StreamReadTimeout)) | |||
|
|||
ids.handleIdentifyResponse(s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we already set a read deadline in this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have fixed this.
p2p/protocol/identify/id_delta.go
Outdated
@@ -15,6 +16,8 @@ const IDDelta = "/p2p/id/delta/1.0.0" | |||
|
|||
// deltaHandler handles incoming delta updates from peers. | |||
func (ids *IDService) deltaHandler(s network.Stream) { | |||
s.SetReadDeadline(time.Now().Add(StreamReadTimeout)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to explicitly ignore the error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done.
@@ -408,7 +414,9 @@ func (ids *IDService) sendIdentifyResp(s network.Stream) { | |||
log.Debugf("%s sent message to %s %s", ID, c.RemotePeer(), c.RemoteMultiaddr()) | |||
} | |||
|
|||
func (ids *IDService) handleIdentifyResponse(s network.Stream) { | |||
func (ids *IDService) handleIdentifyResponse(s network.Stream) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we returning an error now? There isn't much we can do about it and we appear to always ignore it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to ensure that we publish an EvtPeerIdentificationCompleted
only if the stream read was successful. If the stream read fails, say because of a timeout, we want to publish an EvtPeerIdentificationFailed
event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. We should be returning an error from consumeMessage in that case.
p2p/protocol/identify/id.go
Outdated
} | ||
|
||
func (ids *IDService) sendIdentifyResp(s network.Stream) { | ||
s.SetDeadline(time.Now().Add(StreamReadTimeout)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: using the read timeout here is a bit strange, this mostly applies to writes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, had put in just in case. Have removed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on which PR gets merged first (this one or #1033), we might need to set the context for OpenStream
here.
@Stebalien Have pushed the changes. |
@@ -408,7 +414,9 @@ func (ids *IDService) sendIdentifyResp(s network.Stream) { | |||
log.Debugf("%s sent message to %s %s", ID, c.RemotePeer(), c.RemoteMultiaddr()) | |||
} | |||
|
|||
func (ids *IDService) handleIdentifyResponse(s network.Stream) { | |||
func (ids *IDService) handleIdentifyResponse(s network.Stream) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. We should be returning an error from consumeMessage in that case.
No description provided.