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 Posix Serial Driver Not Unblocking Read on Close #1166

Merged
merged 1 commit into from
Mar 31, 2024

Conversation

ryanmelt
Copy link
Member

No description provided.

@ryanmelt ryanmelt requested a review from jmthomas March 31, 2024 03:39
Copy link

Quality Gate Passed Quality Gate passed

Issues
1 New issue
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link

codecov bot commented Mar 31, 2024

Codecov Report

Attention: Patch coverage is 0% with 12 lines in your changes are missing coverage. Please review.

Project coverage is 74.99%. Comparing base (b370451) to head (1236092).
Report is 3 commits behind head on main.

Files Patch % Lines
openc3/lib/openc3/io/posix_serial_driver.rb 0.00% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1166      +/-   ##
==========================================
+ Coverage   74.98%   74.99%   +0.01%     
==========================================
  Files         595      595              
  Lines       43914    43922       +8     
  Branches      757      757              
==========================================
+ Hits        32928    32940      +12     
+ Misses      10903    10898       -5     
- Partials       83       84       +1     
Flag Coverage Δ
frontend 55.31% <ø> (+0.09%) ⬆️
python 83.04% <ø> (+0.05%) ⬆️
ruby-api 48.72% <ø> (+0.01%) ⬆️
ruby-backend 80.02% <0.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@jmthomas jmthomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with this technique and how it works.

begin
read_ready, _ = IO.fast_select(@readers, nil, nil, @read_timeout)
rescue IOError
@pipe_reader.close unless @pipe_reader.closed?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how closing the pipe_reader is going to help with the serial port handle

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing the pipe reader is just to make sure we don't leave file handles open. Return "" means that we are dead and should no longer be used going forward. IOError should only occur if the serial port has already been closed.

@pipe_reader.close unless @pipe_reader.closed?
return ""
else
retry
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This jumps back to the read_nonblock right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

if read_ready
if read_ready.include?(@pipe_reader)
@pipe_reader.close unless @pipe_reader.closed?
return ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you close the pipe_reader if the read_ready says it's ready?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pipe_reader is only ever ready, if pipe_writer was written. That means we have been closed.

@ryanmelt
Copy link
Member Author

This mostly the same code from sleeper.rb.
See: https://www.sitepoint.com/the-self-pipe-trick-explained/
for the technique

@ryanmelt ryanmelt merged commit 460e13e into main Mar 31, 2024
24 checks passed
@ryanmelt ryanmelt deleted the fix_posix_serial_driver branch March 31, 2024 04:17
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.

2 participants