-
Notifications
You must be signed in to change notification settings - Fork 11
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
feat: Implement the background mode in Windows. #23
Conversation
8510a74
to
209eb6f
Compare
src/openjd/adaptor_runtime/_background/backend_named_pipe_server.py
Outdated
Show resolved
Hide resolved
src/openjd/adaptor_runtime/_background/backend_named_pipe_server.py
Outdated
Show resolved
Hide resolved
src/openjd/adaptor_runtime/_background/backend_named_pipe_server.py
Outdated
Show resolved
Hide resolved
src/openjd/adaptor_runtime/_background/named_pipe_request_handler.py
Outdated
Show resolved
Hide resolved
src/openjd/adaptor_runtime/_background/named_pipe_request_handler.py
Outdated
Show resolved
Hide resolved
src/openjd/adaptor_runtime/adaptors/configuration/_configuration_manager.py
Outdated
Show resolved
Hide resolved
e51dcab
to
c76753b
Compare
src/openjd/adaptor_runtime/_background/backend_named_pipe_server.py
Outdated
Show resolved
Hide resolved
|
||
# Cleanup the connection file and socket | ||
for path in [self._connection_file_path, socket_path]: | ||
self._server.shutdown() # type: ignore |
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.
I see, we could add a if self._server is not None:
here, I think we generally want to avoid using type: ignore
whenever possible so that our type checking is stronger.
src/openjd/adaptor_runtime/_background/named_pipe_request_handler.py
Outdated
Show resolved
Hide resolved
src/openjd/adaptor_runtime/_background/named_pipe_request_handler.py
Outdated
Show resolved
Hide resolved
c76753b
to
6b1eb07
Compare
src/openjd/adaptor_runtime/adaptors/configuration/_configuration_manager.py
Show resolved
Hide resolved
_logger.info(f"Creating Named Pipe with name: {self._pipe_name}") | ||
# During shutdown, a `True` will be pushed to the `_cancel_queue` for ending this loop | ||
while self._cancel_queue.qsize() == 0: | ||
pipe_handle = self._create_pipe(self._pipe_name) |
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.
Do we need to be creating a new pipe file for every request, or is there a way to reuse the same one? It seems weird to me to only be able to send a single request per pipe.
Also, you're not handling the pipe_handle == None
case here.
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.
-
For the reusing the NamedPipe instance, I will try to explain this. Short answer is there are not simple ways to do that. If we reuse the named pipe instance, this situation may happen, a
run
command is sent to the server followed by astop
command, the response for therun
command may be read by thestop
command. We are creating theNamedPipe instance
here under the sameNamedPipe server
. The relationship between aNamedPipe server
and aNamedPipe instance
can be likened to the relationship between anHTTP server
and anHTTP connection
. And in the HTTP/2 connection, they have a technique called multiplexing (multiple requests and responses can be sent concurrently over a single connection). NamedPipe doesn't support this (like HTTP/1).. we can implement this by ourselves if we observe performance issues. -
Good catch, I will handle it in next version.
src/openjd/adaptor_runtime/_background/backend_named_pipe_server.py
Outdated
Show resolved
Hide resolved
6b1eb07
to
ffcc3b6
Compare
ffcc3b6
to
8fd5134
Compare
test/openjd/adaptor_runtime/integ/background/test_background_mode.py
Outdated
Show resolved
Hide resolved
if OSName.is_windows(): | ||
return self._send_windows_request( | ||
method, | ||
path, | ||
params=params if params else None, | ||
json_body=json_body if json_body else None, | ||
) | ||
else: | ||
return self._send_linux_request( | ||
method, | ||
path, | ||
params=params if params else None, | ||
json_body=json_body if json_body else None, | ||
) |
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.
Instead of this pattern, what do you think about specializing this class and having two implementations with an abstract method for _send_request
? e.g. we can have WindowsFrontendRunner
and PosixFrontendRunner
that inherit this base class and only have a _send_request
method (for now)
Then we can move the if windows elif posix
stuff to outside of this class wherever we instantiate the FrontendRunner
.
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.
Yes, similar to above discussion, will do it outside of this PR.
_logger.error( | ||
f"Encountered an error while closing the named pipe: {traceback.format_exc()}" | ||
) | ||
_logger.debug("WinBackgroundResourceRequestHandler instance thread exited.") |
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.
I think we should bump this up to INFO level so it's clear in the logs when this thread exits
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.
This will create lots of unnecessary log because we will create the thread when establishing the connection. I don't think it is necessary to log the information when the instance thread existed. Also we are running the server in multi-thread environment so logging this won't help for debugging because we don't know which thread existed.
src/openjd/adaptor_runtime/_background/backend_named_pipe_server.py
Outdated
Show resolved
Hide resolved
Signed-off-by: Hongli Chen <[email protected]>
8fd5134
to
150270a
Compare
Daniel is out this week and I already addressed his comments and for the optimization part, I will do it outside of this PR.
What was the problem/requirement? (What/Why)
Background mode is missing in the Windows, we need to implement it.
What was the solution? (How)
TODO
in this PR. Those missing function will be added later to the package. I just want to limit the changes in a single PR for easily reviewed.What is the impact of this change?
Background mode can be run in Windows.
How was this change tested?
Enable the related integration test and all of them are passed.
Was this change documented?
Yes
Is this a breaking change?
No. This change should not affect any existing Linux implementation.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.