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

feat: Implement the background mode in Windows. #23

Merged
merged 2 commits into from
Nov 28, 2023

Conversation

Honglichenn
Copy link
Contributor

@Honglichenn Honglichenn commented Nov 14, 2023

What was the problem/requirement? (What/Why)

Background mode is missing in the Windows, we need to implement it.

What was the solution? (How)

  • Use Named Pipe for IPC solution in Windows to implement the background mode.
  • There are lots of 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.

@Honglichenn Honglichenn force-pushed the honglich/win_backend branch 30 times, most recently from 8510a74 to 209eb6f Compare November 16, 2023 22:25
@Honglichenn Honglichenn marked this pull request as ready for review November 16, 2023 23:14
@Honglichenn Honglichenn requested a review from a team as a code owner November 16, 2023 23:14
@Honglichenn Honglichenn force-pushed the honglich/win_backend branch 2 times, most recently from e51dcab to c76753b Compare November 17, 2023 21:33

# Cleanup the connection file and socket
for path in [self._connection_file_path, socket_path]:
self._server.shutdown() # type: ignore
Copy link
Contributor

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/frontend_runner.py Outdated Show resolved Hide resolved
src/openjd/adaptor_runtime/application_ipc/__init__.py Outdated Show resolved Hide resolved
src/openjd/adaptor_runtime/_background/backend_runner.py Outdated Show resolved Hide resolved
src/openjd/adaptor_runtime/_background/frontend_runner.py Outdated 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)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. 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 a stop command, the response for the run command may be read by the stop command. We are creating the NamedPipe instance here under the same NamedPipe server. The relationship between a NamedPipe server and a NamedPipe instance can be likened to the relationship between an HTTP server and an HTTP 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.

  2. Good catch, I will handle it in next version.

AWS-Samuel
AWS-Samuel previously approved these changes Nov 20, 2023
Comment on lines +237 to +251
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,
)
Copy link
Contributor

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.

Copy link
Contributor Author

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.")
Copy link
Contributor

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

Copy link
Contributor Author

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.

@Honglichenn Honglichenn requested a review from jericht November 28, 2023 17:30
@Honglichenn Honglichenn dismissed ddneilson’s stale review November 28, 2023 19:13

Daniel is out this week and I already addressed his comments and for the optimization part, I will do it outside of this PR.

@Honglichenn Honglichenn merged commit ac80ce7 into mainline Nov 28, 2023
9 checks passed
@Honglichenn Honglichenn deleted the honglich/win_backend branch November 28, 2023 19:13
@ddneilson ddneilson added the security Pull requests that could impact security label Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
security Pull requests that could impact security
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants