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

[WIP] Implement Dropwizard Unix socket connector #1893

Closed
wants to merge 17 commits into from

Conversation

arteam
Copy link
Member

@arteam arteam commented Jan 18, 2017

This pull requests some basic work for supporting a Unix Socket connector in Dropwizard. The implementation seems to be rather simple, but I stumled on some problems:

  • I wasn't able to run a server in the default mode because of some admin thread pool management issues.
  • The server doesn't shut down gracefully. It waits 30 seconds and then killed forcefully after a SIGTERM signal is sent.

The original issue is #1889.

@arteam arteam force-pushed the dropwizard_unix_sockets branch 3 times, most recently from 3525675 to b577d32 Compare January 18, 2017 09:11
@arteam
Copy link
Member Author

arteam commented Jan 18, 2017

Regarding the second error I believe we affected by jetty/jetty.project#1044.
Linux native poll connector returns a null SelectionKey at some moment during graceful shutdown.

DEBUG [2017-01-18 09:36:19,876] org.eclipse.jetty.io.ManagedSelector: Could not run action org.eclipse.jetty.io.ManagedSelector$CloseEndPoints@38d525aa
! java.lang.NullPointerException: null
! at org.eclipse.jetty.io.ManagedSelector$CloseEndPoints.run(ManagedSelector.java:761)
! at org.eclipse.jetty.io.ManagedSelector$SelectorProducer.nextAction(ManagedSelector.java:284)
! at org.eclipse.jetty.io.ManagedSelector$SelectorProducer.produce(ManagedSelector.java:248)
! at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:147)
! at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:133)
! at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:672)
! at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:590)

@JsonTypeName("unixsocket")
public class UnixSocketFactory extends HttpConnectorFactory {

private String socketFilename = "/tmp/dropwizard.sock";
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we prefer /var/run/dropwizard.sock (Stackoverflow)?

Copy link
Member Author

@arteam arteam Jan 18, 2017

Choose a reason for hiding this comment

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

That's a good idea.

Copy link
Member Author

@arteam arteam Jan 18, 2017

Choose a reason for hiding this comment

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

After the second thought, it looks not so good. Not every process has enough permissions to write to the /var/run directory. I believe, you need to have a special directory under /var/run with the permissions for the user which runs the process.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that's fine. If I were using unix sockets I'd most likely change the socket location anyways...to something like /var/run/<servicename>.sock. But it may be something to add in the documentation (eg. normally unix domain sockets are in /var/run, but since we may not be running as root or have adequate permissions, store the file in /tmp)

import java.io.Reader;
import java.nio.channels.Channels;

public class UnixSocketConnectorFactoryTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

May need to disable this test for windows builds, no?

* </tr>
* <tr>
* <td>{@code socketFilename}</td>
* <td></tmp/dropwizard.sock</td>
Copy link
Member

Choose a reason for hiding this comment

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

there's an extra < in here

@nickbabcock
Copy link
Contributor

jetty-9.4.1.v20170120 is out and fixes the timeout issue, though it doesn't fix the bug where socket errors arise under load

@arteam
Copy link
Member Author

arteam commented Feb 19, 2018

I think the bug in the jnr library hasn't been fixed. I believe I submitted a PR for a while: jnr/jnr-enxio#25

@jplock jplock added this to the 2.0.0 milestone Jul 27, 2018
@jplock jplock added the feature label Jul 27, 2018
@joschi joschi added the blocked label Jul 30, 2018

@Before
public void setUp() {
assumeFalse(SystemUtils.IS_OS_WINDOWS);
Copy link
Member

@joschi joschi Jul 30, 2018

Choose a reason for hiding this comment

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

Does anyone have an idea why this doesn't seem to work on AppVeyor?

https://ci.appveyor.com/project/arteam/dropwizard/build/1836#L10337

[ERROR] testManyClientCalls(io.dropwizard.unixsocket.UnixSocketConnectorFactoryTest)  Time elapsed: 1.795 s  <<< ERROR!
java.lang.UnsatisfiedLinkError: 
The operation completed successfully.
[ERROR] testClient(io.dropwizard.unixsocket.UnixSocketConnectorFactoryTest)  Time elapsed: 0 s  <<< ERROR!
java.lang.UnsatisfiedLinkError: 
The operation completed successfully.

Copy link
Contributor

Choose a reason for hiding this comment

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

By UnsatisfiedLinkError looks like that native method not found.
Maybe you have to specify image to run maven in appveyor, e.g. image: ubuntu

Here more info:
https://www.appveyor.com/docs/getting-started-with-appveyor-for-linux/#running-your-build-on-linux

Copy link
Member

Choose a reason for hiding this comment

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

@alex-shpak The whole point of using AppVeyor is to make sure that Dropwizard can be built on Windows. 😉

From my understanding, the assumption in the @Before method should prevent all tests from running on Windows. But that doesn't seem to work. 🤔

Copy link
Contributor

@nickbabcock nickbabcock Jul 30, 2018

Choose a reason for hiding this comment

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

Try:

    @BeforeClass
    public static void setUp() {
        assumeFalse(SystemUtils.IS_OS_WINDOWS);
    }

Edit: (that made the test ignored on my windows machine)

Copy link
Member

Choose a reason for hiding this comment

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

@jplock
Copy link
Member

jplock commented Jul 31, 2018

@arteam @joschi @nickbabcock this all set? tests passed 👍 💯 🎉

@joschi
Copy link
Member

joschi commented Jul 31, 2018

@jplock I'd like to wait for the pull request in jnr/jnr-enxio to be merged until we merge this PR.

Additionally, the tests in UnixSocketConnectorFactoryTest don't have any assertions right now and should be reworked.

But at least the branch now builds on all of our CI systems. 😉

@arteam
Copy link
Member Author

arteam commented Aug 2, 2018

It looks like Jetty fixed their integration issues with jnr, and I don't see 30 seconds timeouts during shutdown. I don't know anything about socket errors under load, haven't done any performance testing.

@nickbabcock
Copy link
Contributor

I don't know anything about socket errors under load, haven't done any performance testing.

Don't worry, I did the load test in the jetty issue: jetty/jetty.project#1281 and no errors arose.

@MadalinaPatrichi
Copy link

MadalinaPatrichi commented Feb 6, 2019

Is this going to be merged in? It would be awesome to have this feature in

@joschi
Copy link
Member

joschi commented Feb 7, 2019

@MadalinaPatrichi We currently don't plan to push this further.

If you're interested in this feature, it would be great if you could help us work out the problems with this PR.

@natnan
Copy link
Contributor

natnan commented Feb 24, 2019

What are the current problems? Travis builds and no assertions in UnixSocketConnectorFactoryTest?

@joschi
Copy link
Member

joschi commented Feb 24, 2019

What are the current problems? Travis builds and no assertions in UnixSocketConnectorFactoryTest?

@natnan Yes, pretty much the missing test coverage, the flaky tests, and some transitive dependency foobar.

@joschi
Copy link
Member

joschi commented Feb 24, 2019

I'm a bit hesitant to invest more time into this, given that it's not a stable feature in Jetty.

jetty/jetty.project#3136 (comment)

first let me say that UnixSocket support in Jetty is at best experimental, at worst it is neglected and close to being ejected. We stopped working on the unix socket connector when JNR was not being maintained and our PRs to them were not being accepted.

@joschi
Copy link
Member

joschi commented Feb 24, 2019

@dropwizard/committers Anyone wants to chime in? Otherwise I'd close this PR unless it's working reliably and the UNIX socket support in Jetty becomes stable.

@nickbabcock
Copy link
Contributor

Yeah an relying on an experimental feature would be shaky. I'm in favor of closing and re-evaluating in the future.

@jplock jplock removed this from the 2.0.0 milestone Feb 24, 2019
@joschi
Copy link
Member

joschi commented Mar 3, 2019

Closed due to experimental feature in upstream project.

@joschi joschi closed this Mar 3, 2019
@joschi joschi deleted the dropwizard_unix_sockets branch March 3, 2019 12:56
@natan-abolafya
Copy link
Contributor

natan-abolafya commented Sep 27, 2023

hey there. this can potentially be revived now considering it's not experimental anymore: https://webtide.com/unixdomain-support-in-jetty/
I applied the code here with some adjustments to our application and it seems to be functioning well. Though I haven't done any stress testing or anything.

@joschi
Copy link
Member

joschi commented Oct 4, 2023

@natan-abolafya Thanks for looking into this.

Would you like to create a pull request against the release/4.0.x branch with the updated implementation?

@natan-abolafya
Copy link
Contributor

Will be very happy to try. I should be able to look into it probably early next week.

joschi pushed a commit that referenced this pull request Jan 26, 2024
Co-authored-by: Steffen Nießing <zuniquex@protonmail.com>

###### Problem:
Since Java 16, Unix Domain Sockets are supported natively. And since Jetty 10, there is a ready made connector for it and it is not considered experimental anymore.

The typical use case is a reverse proxy connecting to UNIX socket instead of TCP which has various advantages.

###### Solution:
Created a new connector type `unix-socket`.

I've reimplemented #1893 but it needed some adjustments considering how much Dropwizard changed since then.

The test was also a little tricky (and not very pretty) considering there is no UNIX socket support in Apache HTTP client. Or at least I couldn't find any but please correct me otherwise.

###### Result:
It's pretty simple to listen on unix sockets now. That was something we wanted in our product for a long time.
Also this works on Windows since Windows now also supports UNIX domain sockets.

Refs #1893
joschi pushed a commit that referenced this pull request Jan 26, 2024
Co-authored-by: Steffen Nießing <zuniquex@protonmail.com>

Since Java 16, Unix Domain Sockets are supported natively. And since Jetty 10, there is a ready made connector for it and it is not considered experimental anymore.

The typical use case is a reverse proxy connecting to UNIX socket instead of TCP which has various advantages.

Created a new connector type `unix-socket`.

I've reimplemented #1893 but it needed some adjustments considering how much Dropwizard changed since then.

The test was also a little tricky (and not very pretty) considering there is no UNIX socket support in Apache HTTP client. Or at least I couldn't find any but please correct me otherwise.

It's pretty simple to listen on UNIX sockets now. That was something we wanted in our product for a long time.
Also this works on Windows since Windows now also supports UNIX domain sockets.

Refs #1893
Refs #7614
(cherry picked from commit 1de3eef)
joschi pushed a commit that referenced this pull request Jan 26, 2024
Co-authored-by: Steffen Nießing <zuniquex@protonmail.com>

Since Java 16, Unix Domain Sockets are supported natively. And since Jetty 10, there is a ready made connector for it and it is not considered experimental anymore.

The typical use case is a reverse proxy connecting to UNIX socket instead of TCP which has various advantages.

Created a new connector type `unix-socket`.

I've reimplemented #1893 but it needed some adjustments considering how much Dropwizard changed since then.

The test was also a little tricky (and not very pretty) considering there is no UNIX socket support in Apache HTTP client. Or at least I couldn't find any but please correct me otherwise.

It's pretty simple to listen on UNIX sockets now. That was something we wanted in our product for a long time.
Also this works on Windows since Windows now also supports UNIX domain sockets.

Refs #1893
Refs #7614
(cherry picked from commit 1de3eef)
joschi pushed a commit that referenced this pull request Jan 26, 2024
Co-authored-by: Steffen Nießing <zuniquex@protonmail.com>

Since Java 16, Unix Domain Sockets are supported natively. And since Jetty 10, there is a ready made connector for it and it is not considered experimental anymore.

The typical use case is a reverse proxy connecting to UNIX socket instead of TCP which has various advantages.

Created a new connector type `unix-socket`.

I've reimplemented #1893 but it needed some adjustments considering how much Dropwizard changed since then.

The test was also a little tricky (and not very pretty) considering there is no UNIX socket support in Apache HTTP client. Or at least I couldn't find any but please correct me otherwise.

It's pretty simple to listen on UNIX sockets now. That was something we wanted in our product for a long time.
Also this works on Windows since Windows now also supports UNIX domain sockets.

Refs #1893
Refs #7614
(cherry picked from commit 1de3eef)
joschi pushed a commit that referenced this pull request Jan 26, 2024
Co-authored-by: Steffen Nießing <zuniquex@protonmail.com>

Since Java 16, Unix Domain Sockets are supported natively. And since Jetty 10, there is a ready made connector for it and it is not considered experimental anymore.

The typical use case is a reverse proxy connecting to UNIX socket instead of TCP which has various advantages.

Created a new connector type `unix-socket`.

I've reimplemented #1893 but it needed some adjustments considering how much Dropwizard changed since then.

The test was also a little tricky (and not very pretty) considering there is no UNIX socket support in Apache HTTP client. Or at least I couldn't find any but please correct me otherwise.

It's pretty simple to listen on UNIX sockets now. That was something we wanted in our product for a long time.
Also this works on Windows since Windows now also supports UNIX domain sockets.

Refs #1893
Refs #7614
(cherry picked from commit 1de3eef)
joschi pushed a commit that referenced this pull request Jan 26, 2024
Co-authored-by: Steffen Nießing <zuniquex@protonmail.com>

Since Java 16, Unix Domain Sockets are supported natively. And since Jetty 10, there is a ready made connector for it and it is not considered experimental anymore.

The typical use case is a reverse proxy connecting to UNIX socket instead of TCP which has various advantages.

Created a new connector type `unix-socket`.

I've reimplemented #1893 but it needed some adjustments considering how much Dropwizard changed since then.

The test was also a little tricky (and not very pretty) considering there is no UNIX socket support in Apache HTTP client. Or at least I couldn't find any but please correct me otherwise.

It's pretty simple to listen on UNIX sockets now. That was something we wanted in our product for a long time.
Also this works on Windows since Windows now also supports UNIX domain sockets.

Refs #1893
Refs #7614
(cherry picked from commit 1de3eef)
joschi pushed a commit that referenced this pull request Jan 26, 2024
Co-authored-by: Steffen Nießing <zuniquex@protonmail.com>

Since Java 16, Unix Domain Sockets are supported natively. And since Jetty 10, there is a ready made connector for it and it is not considered experimental anymore.

The typical use case is a reverse proxy connecting to UNIX socket instead of TCP which has various advantages.

Created a new connector type `unix-socket`.

I've reimplemented #1893 but it needed some adjustments considering how much Dropwizard changed since then.

The test was also a little tricky (and not very pretty) considering there is no UNIX socket support in Apache HTTP client. Or at least I couldn't find any but please correct me otherwise.

It's pretty simple to listen on UNIX sockets now. That was something we wanted in our product for a long time.
Also this works on Windows since Windows now also supports UNIX domain sockets.

Refs #1893
Refs #7614
(cherry picked from commit 1de3eef)
joschi added a commit that referenced this pull request Jan 26, 2024
Co-authored-by: Steffen Nießing <zuniquex@protonmail.com>
Co-authored-by: Natan Abolafya <natan.abolafya@appgate.com>

Since Java 16, Unix Domain Sockets are supported natively. And since Jetty 10, there is a ready made connector for it and it is not considered experimental anymore.

The typical use case is a reverse proxy connecting to UNIX socket instead of TCP which has various advantages.

Created a new connector type `unix-socket`.

I've reimplemented #1893 but it needed some adjustments considering how much Dropwizard changed since then.

The test was also a little tricky (and not very pretty) considering there is no UNIX socket support in Apache HTTP client. Or at least I couldn't find any but please correct me otherwise.

It's pretty simple to listen on UNIX sockets now. That was something we wanted in our product for a long time. Also this works on Windows since Windows now also supports UNIX domain sockets.

Refs #1893
Refs #7614
(cherry picked from commit 1de3eef)
joschi added a commit that referenced this pull request Jan 26, 2024
Co-authored-by: Steffen Nießing <zuniquex@protonmail.com>
Co-authored-by: Natan Abolafya <natan.abolafya@appgate.com>

Since Java 16, Unix Domain Sockets are supported natively. And since Jetty 10, there is a ready made connector for it and it is not considered experimental anymore.

The typical use case is a reverse proxy connecting to UNIX socket instead of TCP which has various advantages.

Created a new connector type `unix-socket`.

I've reimplemented #1893 but it needed some adjustments considering how much Dropwizard changed since then.

The test was also a little tricky (and not very pretty) considering there is no UNIX socket support in Apache HTTP client. Or at least I couldn't find any but please correct me otherwise.

It's pretty simple to listen on UNIX sockets now. That was something we wanted in our product for a long time. Also this works on Windows since Windows now also supports UNIX domain sockets.

Refs #1893
Refs #7614
(cherry picked from commit 1de3eef)
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.

None yet

8 participants