-
Notifications
You must be signed in to change notification settings - Fork 100
#189 Zero byte read from NFS - Fix method file_read in watched_file.rb #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,8 +89,27 @@ def file_seek(amount, whence = IO::SEEK_SET) | |
end | ||
|
||
def file_read(amount) | ||
set_accessed_at | ||
@file.sysread(amount) | ||
#debug "*** file_read #{path}" | ||
cc = 3 # max attempts | ||
dt = 1.0/128 # delay beetwen attempts | ||
loop do | ||
set_accessed_at | ||
buf = @file.sysread(amount) | ||
# return if no zero byte inside | ||
return buf unless zc = buf.index("\0") | ||
# update amount to read | ||
amount = buf.bytesize | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
# warn "*** ZERO-#{cc} byte (#{zc} of #{amount}) in #{path}" | ||
cc -= 1 | ||
# was last attempt - returning buffer with zero byte | ||
return buf if cc.zero? | ||
# sllep before next read | ||
sleep(dt) | ||
# increase sleep time | ||
dt *= 4 | ||
# get back in file | ||
@file.sysseek(-amount, IO::SEEK_CUR) | ||
end | ||
end | ||
|
||
def file_open? | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
zc
variable is bound, but unused.Additionally, for readability we prefer that variables are descriptive and unabiguous, and while I can tell what
buf
is, variables likecc
anddt
would be better off with more descriptive names likeattempts_remaining
andbackoff_delay
.