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

Cleanup of exec streams #4115

Merged
merged 1 commit into from May 11, 2022
Merged

Cleanup of exec streams #4115

merged 1 commit into from May 11, 2022

Conversation

shawkins
Copy link
Contributor

@shawkins shawkins commented May 2, 2022

Description

A draft built on top of #4110 - with the refinements of:

  • removing usage of piped streams - from both the api and internal usage. They make assumptions about threads that we should not guarantee. Added checks to see if piped streams are passed in and throw an exception (you could of course wrap the stream in something else and it can make it through) and updated the javadocs to indicate that they shouldn't be used.
  • adding backpressure support
  • adding javadocs to stream methods
  • exposing terminate on error

The code changes seem mostly complete - I'll add more tests and update the migration guide as well.

In general using multiple InputStream redirects (output, error, errorChannel) is dangerous - even when using okhttp. The streams are not independent as they all share the same websocket / listener. If they are not all read independently you run the risk of a deadlock. I did not go so far as to to enforce only a single one of these methods can be called - but it might be a good idea.

Other api changes:

TtyExecOutputErrorable readingInput(InputStream in) - should be deprecated. That requires us to use a separate thread pool and a pumper, it also only works if the stream supports available(), and does not provide an indication of when the stream has been fully consumed. It should be up to the caller instead to use redirectInput and the ExecWatch OutputStream.

Writing or redirecting the errorChannel should be deprecated - there is now the exitcode future and the onExit methods that can be used instead.

If it seems desirable another type of stream handler could be added, which would more closely resemble the MessageHandler void handle(ByteBuffer bytes) throws IOException method - but it would likely need some additional context, such as the ExecWatch and a way to indicate the byte buffer had been consumed to pull the next results. That seemed sufficiently complex that I decided against exposing something like that.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Checklist

  • Code contributed by me aligns with current project license: Apache 2.0
  • I Added CHANGELOG entry regarding this change
  • I have implemented unit tests to cover my changes
  • I have added/updated the javadocs and other documentation accordingly
  • No new bugs, code smells, etc. in SonarCloud report
  • I tested my code in Kubernetes
  • I tested my code in OpenShift

removing usage of piped streams
adding backpressure support
adding javadocs to stream methods
exposing terminate on error
also updating the exec examples
@shawkins shawkins marked this pull request as ready for review May 6, 2022 13:29
@sonarcloud
Copy link

sonarcloud bot commented May 6, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug E 2 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 12 Code Smells

47.4% 47.4% Coverage
0.0% 0.0% Duplication

@manusa manusa added this to the 6.0.0 milestone May 11, 2022
@manusa manusa merged commit de7e27a into fabric8io:master May 11, 2022
@manusa
Copy link
Member

manusa commented May 17, 2022

Hi @shawkins,

Likely not related to this PR or its specific changes, but maybe to the broader changes we've done to stream processing.

We're starting to get test failures related to port forward tests. I've also experienced some issues when using the latest SNAPSHOT with a demo project.

image

Do you have any idea what might be causing these issues?

@shawkins
Copy link
Contributor Author

@manusa should be addressed by #4150 - that changes where the calls to request more events are made https://github.com/fabric8io/kubernetes-client/pull/4150/files#diff-33e24625fc84585d76afb93c4977be3e568a87d7bc2170362d2f6447e5371cebR229

That should mean that the write will complete before we see the close event.

@manusa
Copy link
Member

manusa commented May 18, 2022

We've made changes to the method location a few times, I recall a similar problem with the Watchers too. We need to find a proper, non-flaky way to test this 😓

@shawkins
Copy link
Contributor Author

We've made changes to the method location a few times

Moving forward it should hopefully be addressed. The changes for backpressure support should effectively serialize the processing so that we can't process close until we're done processing the streams.

@manusa
Copy link
Member

manusa commented May 18, 2022

I created some tests that verify the specific behavior of the PortForwarderWebsocketListener:

#4159

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.

None yet

2 participants