data_timeout: decouple blocking duration from data timeout #30
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.
RETROACTIVE EDIT TO HIGHLIGHT ISSUE
v3.1.1 of this plugin made changes to attempt to make the plugin more-interruptible, but had the undesired side-effect of very high CPU in the default configuration of
data_timeout => -1
(no timeout, read repeatedly until socket stops existing).A workaround was suggested along with the bug report to set the
data_timeout
to a very high number (like315360000
"ten years") which prevents the high-CPU issue, but a plugin in this configuration connected to a socket that was not receiving traffic could not be interrupted because it is blocking onIO#Select
for the entiredata_timeout
and not checking for plugin shutdown state.In order to both observe shutdown state and the default no-timeout for the data channel, we need to decouple blocking IO limits from our
data_timeout
.Introduces
Unix#io_interruptable_readpartial
, which emulatesIO#readpartial
while observing both the plugin's stop condition and an optional timeout.Internally, this helper limits its blocking calls to 10s or less whether or not the plugin is configured with a
data_timeout
, allowing it to periodically observe the plugin's stop condition to exit gracefully in a reasonable amount of time when the socket is not receiving writes.This fixes a regression introduced in v3.1.1 of this plugin (#29) in which the default configuration of
data_timeout => -1
(timeout disabled) consumed excess CPU attempting non-blocking reads of the IO when it had no readable bytes.