RequestServer.Serve bugs found looking at PR-361 #363
Merged
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.
So, I end up moving the “tautological statement” into a function under
Request
(transferError(err error)
). The new function better encapsulates behavior of theRequest
object to calls on theRequest
object. So, while the check now still exists, it at least is an appropriate guard statement, guarding against potential misbehavior.The thing I noticed during PR-361, is that the
break
in theswitch { default: … }
does not break out of thefor { … }
loop, but rather only out of theswitch
. Meaning, thebreak
as it originally appeared was actually a no-op, and execution wasn’t properly ending in that situation.The solution was to move the
for { … }
loop into its own independent function, where the loop can then be broken clearly and unambiguously with areturn
.Additionally, I noticed that although we’re looping over
openRequests
, which is supposed to only be accessed under lock, we were not actually holding the lock at that point.As well,
Request.Close
really should be closing both thereaderAt
and thewriterAt
if they implement,io.Closer
, even if the first one returns anerr != nil
error.