We cannot avoid continuing to call SetReadDeadline and similar methods after the connection is closed. #1835
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the current implementation, there are several places where it's assumed that SetReadDeadline and similar functions logically won't affect a closed connection. However, these assumptions may not hold in certain specific situations. Therefore, instead of asserting that such errors will never occur, simply return the errors encountered during the execution of these methods.
The current implementation of ShutDown can, under certain conditions, invalidate these assumptions.
Case 1
fasthttp/server.go
Lines 1600 to 1609 in d29a2b9
We cannot assume that when the program reaches this point, the connection state has not yet transitioned from StateNew to the actual StateIdle. Even if this transition takes 5 seconds, we cannot make assumptions about the scheduler without synchronization primitives.
Case 2
fasthttp/server.go
Lines 2136 to 2146 in d29a2b9
What ensures that getNextProto doesn't take longer than 5 seconds to execute?
Case 3
fasthttp/server.go
Lines 2262 to 2267 in d29a2b9
If neither Server.ReadTimeout nor Server.IdleTimeout are set, and the timeout is configured through Server.HeaderReceived, there is a possibility that the connection might be closed by ShutDown during the transition from idle to active state.
See Issue: #1815
Case 4
fasthttp/server.go
Lines 2403 to 2414 in d29a2b9
If there's buffered data in the underlying connection or in br, and bw.Flush hasn't been executed before, it's not guaranteed that the underlying connection's closure will be observed by the code executed previously.