Skip to content
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

Merged
merged 3 commits into from
Jan 14, 2021
Merged

Timeout all Identify stream reads #1032

merged 3 commits into from
Jan 14, 2021

Conversation

aarshkshah1992
Copy link
Contributor

No description provided.

ids.handleIdentifyResponse(s)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^

@@ -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)
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have fixed this.

@@ -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))
Copy link
Member

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.

Copy link
Contributor Author

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 {
Copy link
Member

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.

Copy link
Contributor Author

@aarshkshah1992 aarshkshah1992 Dec 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Stebalien

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.

Copy link
Member

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.

}

func (ids *IDService) sendIdentifyResp(s network.Stream) {
s.SetDeadline(time.Now().Add(StreamReadTimeout))
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@marten-seemann marten-seemann left a 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.

@aarshkshah1992
Copy link
Contributor Author

@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 {
Copy link
Member

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.

@aarshkshah1992 aarshkshah1992 merged commit 1c850e1 into master Jan 14, 2021
@aarshkshah1992 aarshkshah1992 deleted the fix/id-timeout branch January 14, 2021 06:17
@Stebalien Stebalien mentioned this pull request May 11, 2021
27 tasks
@aschmahmann aschmahmann mentioned this pull request May 14, 2021
71 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants