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

fix: add deadlines to write and read requests #81

Closed
wants to merge 2 commits into from
Closed

Conversation

Kubuxu
Copy link
Member

@Kubuxu Kubuxu commented Aug 12, 2017

Prevents buildup in case of non-responding peers

Prevents buildup in case of non-responding peers
dht_net.go Outdated
@@ -178,6 +179,7 @@ func (ms *messageSender) SendMessage(ctx context.Context, pmes *pb.Message) erro
}

func (ms *messageSender) writeMessage(pmes *pb.Message) error {
ms.s.SetWriteDeadline(time.Now().Add(dhtMessageTimeout))
Copy link

Choose a reason for hiding this comment

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

Is the writeDeadline scoped per WriteMsg() call? Otherwise I think we might have to clear the deadline when we're finished with this writeMessage() call.

Copy link
Member Author

Choose a reason for hiding this comment

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

All writes are pretended with it and clearing it would cause race where one write ends and another starts and the starting one gets it deadline cleared.

@ghost
Copy link

ghost commented Aug 12, 2017

One tiny question, otherwise LGTM

@whyrusleeping
Copy link
Contributor

dont forget to reset the deadlines after the write succeeds

@Kubuxu
Copy link
Member Author

Kubuxu commented Aug 12, 2017

I can't reset write deadline, it might race with another set of the deadline (in other goroutine).

Will anything happen if write daedlines are set before every write?

@Stebalien
Copy link
Member

Will anything happen if write daedlines are set before every write?

An extra syscall, probably (depending on the stream multiplexer implementation).

@whyrusleeping
Copy link
Contributor

I can't reset write deadline, it might race with another set of the deadline (in other goroutine).

That shouldnt happen. You shouldnt ever be writing to the same conn from different goroutines.

@Stebalien
Copy link
Member

@whyrusleeping Can one not write to the same stream from multiple goroutines?

@Stebalien
Copy link
Member

To answer my own question, yes (one shouldn't, at least).

@Kubuxu
Copy link
Member Author

Kubuxu commented Aug 31, 2017

An extra syscall, probably (depending on the stream multiplexer implementation).

Thing is that we want those deadlines. I will reformulate my question:
Will anything happen if we don't reset the deadlines but we set deadlines before every write?

@whyrusleeping
Copy link
Contributor

whyrusleeping commented Aug 31, 2017 via email

@Stebalien
Copy link
Member

@whyrusleeping Only if you don't extend the deadline before the next write. This is actually how deadlines are supposed to be used as per the documentation: https://golang.org/pkg/net/#Conn

@Kubuxu
Copy link
Member Author

Kubuxu commented Aug 31, 2017

Also another question:
Are deadlines per stream or per connection? Because if they are per connection it is problematic, even if we reset it.

@Stebalien
Copy link
Member

Per stream. Internally, streams set their deadlines before reading/writing and then unset them afterwards.

@Stebalien
Copy link
Member

(usually, each stream muxer has its own implementation)

@@ -63,6 +64,7 @@ func (dht *IpfsDHT) handleNewMessage(s inet.Stream) {
}

// send out response msg
s.SetWriteDeadline(time.Now().Add(dhtMessageTimeout))
Copy link
Member

Choose a reason for hiding this comment

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

Probably best to fix libp2p/go-mplex#7 first.

@whyrusleeping whyrusleeping added the status/deferred Conscious decision to pause or backlog label Oct 17, 2017
@bigs bigs added optimization status/in-progress In progress and removed status/deferred Conscious decision to pause or backlog labels Sep 11, 2018
@bigs
Copy link
Contributor

bigs commented Sep 11, 2018

do we want to rebase and merge this?

@Stebalien
Copy link
Member

We should probably fix libp2p/go-mplex#7 first. I just keep punting on it.

dht_net.go Outdated
@@ -13,7 +13,7 @@ import (
peer "github.com/libp2p/go-libp2p-peer"
)

var dhtReadMessageTimeout = time.Minute
var dhtMessageTimeout = 1 * time.Minute
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be a const.

@anacrolix
Copy link
Contributor

@Kubuxu do you still there's value in this? I've been messing around with this part of the code so I'm prepared to merge it if so.

@ghost ghost assigned anacrolix Feb 14, 2019
@anacrolix
Copy link
Contributor

I merged master, I could have botched it, I'll look into it if this is still being pursued.

@raulk
Copy link
Member

raulk commented Feb 14, 2019

Build failed due to gofmt error.

@Kubuxu
Copy link
Member Author

Kubuxu commented Feb 14, 2019

@anacrolix I think few deadlines with WriteMsg are missing. Can you look over it?

@anacrolix
Copy link
Contributor

I want to clarify: Is the deadline use because Read and Write cannot take contexts, and it's preferable to using "ctxio" and having to terminate the connection to achieve cancellation?

@anacrolix
Copy link
Contributor

This would be unnecessary with #271.

@anacrolix anacrolix removed their assignment Jun 4, 2020
@Stebalien Stebalien closed this Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants