X Tutup
Skip to content

Preserve the order of requests to Docker daemon using DefaultInvocationBuilder (#1492)#1494

Merged
bsideup merged 6 commits intodocker-java:masterfrom
tejksat:alexander.koshevoy/guaranteeConsecutiveRequestsWithDefaultInvocationBuilder
Nov 16, 2020
Merged

Preserve the order of requests to Docker daemon using DefaultInvocationBuilder (#1492)#1494
bsideup merged 6 commits intodocker-java:masterfrom
tejksat:alexander.koshevoy/guaranteeConsecutiveRequestsWithDefaultInvocationBuilder

Conversation

@tejksat
Copy link
Copy Markdown
Contributor

@tejksat tejksat commented Nov 16, 2020

The problem is that using awaitStarted() on attach's callback on a non-running container leads to the infinite wait for Jersey transport implementation.

This happens when SelectiveLoggingFilter is used in DefaultInvocationBuilder where it is created with printEntity = true parameter. In this case the implementation of ClientResponseFilter.filter(...) method in the base LoggingFilter class blocks at responseContext.hasEntity() until the data is available in the response. This happens because hasEntity() reads a single byte to check whether there is any data available in the stream. In the case of attach command this method blocks until there is data in stdout/stderr streams. Having data from the streams requires container running, which we cannot do safely without awaitStarted() because attach command is performed in a separate thread and we need to run start only after attach request is executed not to loose the data from stdout/stderr streams.

thread.start();

try {
onStart.await();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

callback's onStart should be used to detect started operation. Blocking here is an unexpected behaviour change

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also see awaitStarted on ResultCallbackTemplate

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the possible confusion: onStart is CountDownLatch here actually. I will rename it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

my point is that DefaultInvocationBuilder should not be changed. Instead, the callee should use awaitStarted() or similar means

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you, I got it now. I thought there will be inconsistency with other post and get methods of DefaultInvocationBuilder which do not accept ResultCallback as a parameter. The requests in these cases are executed in the same thread and awaitStarted() is not required. But this is the expected behavior?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Those that have no ResultCallback as a parameter are blocking methods, while ResultCallback-based ones are kinda asynchronous, hence no blocking behaviour

Copy link
Copy Markdown
Member

@bsideup bsideup left a comment

Choose a reason for hiding this comment

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

👍

`attachContainerStdinUnsupported()` test requires neither starting the container nor waiting on `awaitStarted()` of attach's callback.
Restore starting the container in the test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

X Tutup