haskell / network

Low-level networking interface
http://hackage.haskell.org/package/network
Other
322 stars 186 forks source link

making gracefulClose more graceful #580

Closed kazu-yamamoto closed 1 month ago

kazu-yamamoto commented 1 month ago

200ms is too long. So, wait for 1ms first, then 2ms, 4ms, 8ms, etc.

kazu-yamamoto commented 1 month ago

@khibino This makes dug's time rag smaller. But we can still notice the time rag, I guess.

@edsko network-run uses gracefulClose in network. We feel a time rag when a client is finished because threadDelay with 200ms is used. This patch starts with 1ms and increments it exponentially.

Your opinions are highly welcome.

edsko commented 1 month ago

Makes sense to me. I don't know how critical the maximum timeout out; as it stands, the patch might exceed it (by one round); could instead consider

let tmout' = tmout + delay
when (r == -1 && tmout' < tmout0) $ do
    threadDelay (delay * 1000)
    loop (delay * 2) tmout'

to check if the timeout that we are about to do would not exceed the max. But it probably doesn't really matter either way.

TL;DR: Fine with me :)

kazu-yamamoto commented 1 month ago

@edsko Thank you for your review. I would like to merge this PR as is.

kazu-yamamoto commented 1 month ago

Rebased and merged.