You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's ignore the fact that test hangs for 10 minutes until that timeout expires; that a different minor problem. The real problem is the "pending byte counts underflow", which indicates that the BufferedIoOutputStream somehow managed to write more data than was passed to it.
This is a race condition between BufferedIoOutputStream.startWriting() and BufferedIoOutputStream.finishWrite(). The following sequence of events is possible when a write that was in progress just finished and the user of the stream just initiates a new write:
Thread 1: startWriting gets the head of the write queue -- this is still the future/buffer that was just written
Thread 2: finishWrite removes that write from the write queue
Thread 2: finishWrite clears the "current" write
Thread 1: startWriting sets the "current" write and happily writes the future/buffer again.
Combined with the fact that the underlying ChannelAsyncOutputStream may in some cases copy the buffer and actually write that copy, but doesn't consume the original buffer in that case, this leads to the same data being written again, and when that second write finishes, this byte count gets subtracted again from the number of total bytes to be written. So the count is added once but subtracted twice, and eventually this "pending byte counts underflow" is hit.
This race condition in BufferedIoOutputStream needs to be fixed. Optionally ChannelAsyncOutputStream should consume the original buffer if it makes a copy; though I'm undecided on that: if it did, it might have hidden this bug (because then the second write of that buffer would have been a zero-byte write).
(The problem is not specific to the MINA transport back-end; it also occurs with NIO2 from time to time. CI builds are green because the race condition appears to be hit infrequently, and on a re-run the test usually succeeds.)
The text was updated successfully, but these errors were encountered:
SFTP tests are flaky. Turns out that they are running into
Let's ignore the fact that test hangs for 10 minutes until that timeout expires; that a different minor problem. The real problem is the "pending byte counts underflow", which indicates that the
BufferedIoOutputStream
somehow managed to write more data than was passed to it.This is a race condition between
BufferedIoOutputStream.startWriting()
andBufferedIoOutputStream.finishWrite()
. The following sequence of events is possible when a write that was in progress just finished and the user of the stream just initiates a new write:startWriting
gets the head of the write queue -- this is still the future/buffer that was just writtenfinishWrite
removes that write from the write queuefinishWrite
clears the "current" writestartWriting
sets the "current" write and happily writes the future/buffer again.Combined with the fact that the underlying
ChannelAsyncOutputStream
may in some cases copy the buffer and actually write that copy, but doesn't consume the original buffer in that case, this leads to the same data being written again, and when that second write finishes, this byte count gets subtracted again from the number of total bytes to be written. So the count is added once but subtracted twice, and eventually this "pending byte counts underflow" is hit.This race condition in
BufferedIoOutputStream
needs to be fixed. OptionallyChannelAsyncOutputStream
should consume the original buffer if it makes a copy; though I'm undecided on that: if it did, it might have hidden this bug (because then the second write of that buffer would have been a zero-byte write).(The problem is not specific to the MINA transport back-end; it also occurs with NIO2 from time to time. CI builds are green because the race condition appears to be hit infrequently, and on a re-run the test usually succeeds.)
The text was updated successfully, but these errors were encountered: