Skip to content

Reuse named pipe sockets - #3493

Merged
randomanderson merged 2 commits into
masterfrom
landerson/named-pipe-uniqueness
Jul 7, 2022
Merged

randomanderson merged 2 commits into
masterfrom
landerson/named-pipe-uniqueness

Conversation

@randomanderson

Copy link
Copy Markdown
Contributor

What Does This Do

Named pipe sockets are stored in a map and reused when requesting the same named pipe.

Motivation

Named pipes can be opened at most twice (1 client and 1 server). The previous implementation did not take that into account. Different subsystems (tracing, statsd, profiling, etc) opened their own named pipe sockets. This lead to a race where the first subsystem was able to use the named pipe and the rest were not.

Additional Notes

This is untested because we have an inability to test on windows.

@randomanderson
randomanderson requested a review from a team as a code owner April 11, 2022 16:44

// Use enum singleton pattern.
// This ensures there is at most one INSTANCE per jvm
private enum SingletonHolder {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This feels like unnecessary boilerplate for what is essentially

private static final Map<File, NamedPipeSocket> fileToSocket = new HashMap<>();

and used like

synchronized(fileToSocket) {
...
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The one benefit of the separate class is that the class initialization lock is basically free. Once initialized, the check will be optimized away by the JIT.

While I know its idiomatic, I don't like using an enum for this because enums while syntactically concise produce really bloated bytecode.

I also probably wouldn't bother with the holder, since we end up needing a synchronized block anyway.

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.

I might have been overly worried about danger of statics being initialized more than once when a class is loaded from multiple classloaders. I checked and NamedPipeSocketFactory is in the shared classloader so this should never be an issue. I'll make the changes.

@randomanderson
randomanderson force-pushed the landerson/named-pipe-uniqueness branch from 4abc163 to 8aa7483 Compare April 29, 2022 17:39
@randomanderson
randomanderson force-pushed the landerson/named-pipe-uniqueness branch from 8aa7483 to 18fa06a Compare July 7, 2022 19:19
@randomanderson
randomanderson requested a review from a team July 7, 2022 20:59
@randomanderson
randomanderson merged commit 643d4f5 into master Jul 7, 2022
@randomanderson
randomanderson deleted the landerson/named-pipe-uniqueness branch July 7, 2022 21:13
@github-actions github-actions Bot added this to the 0.104.0 milestone Jul 7, 2022
@PerfectSlayer PerfectSlayer added tag: performance Performance related changes and removed efficiency labels Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tag: performance Performance related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants