Skip to content
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

Fix race conditions #31

Merged
merged 3 commits into from
Jan 12, 2019
Merged

Fix race conditions #31

merged 3 commits into from
Jan 12, 2019

Conversation

skalee
Copy link
Collaborator

@skalee skalee commented Jan 12, 2019

Strange issues have been reported in riboseinc/enmail#119. Several system calls used to complain about file descriptor issues on a random basis.

It seems that there were some race conditions revolving around how temporary files are managed in this gem. Probably in some situations a temporary file was either partly created/written, or prematurely removed.

Switching from instances of Tempfile class to instances of File did help — the former may be removed by garbage collector, whereas the latter must be removed explicitly. Also, these files are now closed properly after writing their content.

Thanks to these improvements, EnMail builds now always pass for all stable MRI versions from 2.3 to 2.6. However, builds for ruby-head still fail consequently with some file descriptor errors. It is unknown whether it's a regression in Ruby HEAD, or another bug in EnMail, or in this very gem. A thing worth noting is that these builds always fail in the same two examples and LOCs, which is different from previous issues (random failures).

Tempfile.new instantiates Tempfile objects, and handles file deletion
in various situations (i.e. object's finalizer), whereas Tempfile.create
instantiates File objects, and leaves file deletion up to programmer.

Tempfile's surprise file removals were one of the sources of race
conditions.
There is no good reason for keeping file open.

Contrary to #flush, which returns method receiver itself, #close returns
nil.  Hence, a return value must be specified in a following line.
@codecov
Copy link

codecov bot commented Jan 12, 2019

Codecov Report

Merging #31 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #31      +/-   ##
==========================================
+ Coverage   99.26%   99.27%   +<.01%     
==========================================
  Files          11       11              
  Lines         271      274       +3     
==========================================
+ Hits          269      272       +3     
  Misses          2        2
Impacted Files Coverage Δ
lib/rspec/pgp_matchers/gpg_runner.rb 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 87a41b2...ba3d70a. Read the comment docs.

@skalee skalee merged commit c998563 into master Jan 12, 2019
@skalee skalee deleted the fix-race-conditions branch January 12, 2019 18:45
@skalee
Copy link
Collaborator Author

skalee commented Jan 12, 2019

It just happened again… https://travis-ci.org/riboseinc/enmail/jobs/478814305

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant