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

Support Unix Sockets in dart:io #21403

Closed
schultzter opened this issue Oct 23, 2014 · 33 comments
Closed

Support Unix Sockets in dart:io #21403

schultzter opened this issue Oct 23, 2014 · 33 comments
Assignees
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io type-enhancement A request for a change that isn't a bug
Milestone

Comments

@schultzter
Copy link

What steps will clearly show the issue / need for enhancement?

  1. a lot of Unix based systems use Unix sockets for interprocess communication
  2. with dart:io only TCP based communication is possible
  3. support for Unix sockets would greatly increase the integration potential of dart server-side apps

What is the current output?
None, not supported

What would you like to see instead?
Success, connected!

What version of the product are you using? On what operating system?
1.7.2 on Arch Linux

Please provide any additional information below.

@lrhn
Copy link
Member

lrhn commented Oct 24, 2014

Added Library-IO, Area-Library, Triaged labels.

@DartBot
Copy link

DartBot commented Nov 14, 2014

This comment was originally written by @PaulAnnekov


It's very important feature. Unix sockets are lighter than TCP/IP Sockets. They will be useful for nginx + dart setup where you need to proxy requests from nginx to dart server that listens for requests.

@DartBot
Copy link

DartBot commented Apr 20, 2015

This comment was originally written by @kaendfinger


This is a great idea, but I'm pretty sure you can use the Unix "Everything is a file" principle to make it work for now.

@sgjesse
Copy link
Contributor

sgjesse commented Apr 20, 2015

In the dart:io model there is currently no way of creating/listing/deleting a Unix Domain socket, and the also listening is only supported for TCP/IP or UDP.

@DartBot
Copy link

DartBot commented Apr 20, 2015

This comment was originally written by @PaulAnnekov


  1. It's not the right way. I think it's not a big deal for dart developers to add ability to set AF_UNIX socket family in the same way as AF_INET is set. Plus add support for family address as file name. The only problem is backward compatibility with current Dart Socket API.
  2. read() and write() functions are not aliases for recv() and send(). You will have to write a lot of code to repeat all their features using plain I/O functions. "Everything is a file" principle will lead to the wheel reinvention.

@schultzter schultzter added Type-Enhancement library-io area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Apr 20, 2015
@zoechi
Copy link
Contributor

zoechi commented Dec 11, 2015

Any progress on this? I think to remember that I saw a commit or code review where this was mentioned not too long ago, but I might mix up something. I'd like to use this to connect to docker services. It's possible to configure Docker to accept http connections but that results in severe security issues.

@sgjesse
Copy link
Contributor

sgjesse commented Dec 11, 2015

We have been experimenting with adding support for UNIX domain sockets, and is currently using a patched Dart VM for some experimentation. However I don't expect this to be added after all, as we will try to move the experimental use we have back to TCP sockets.

For reference the experimental patch is here: https://codereview.chromium.org/1293533002/.

@zoechi
Copy link
Contributor

zoechi commented Dec 11, 2015

@sgjesse Thanks a lot for this quick response!
Doesn't seem to add a lot of complexity.
What are the reasons for this changes being dropped?

@sgjesse
Copy link
Contributor

sgjesse commented Dec 11, 2015

The change is not complete - it is missing changes to the File class where
we currently also don't handle domain sockets (the patch have a hack to
allow one to delete this type of files).

Another concern is to add platform specific APIs dart:io. If this should be
abstracted to also have a Windows counterpart we would have to find a
matching IPC concept on Windows, which would increase the complexity quite
a bit.

On Fri, Dec 11, 2015 at 12:44 PM, Günter Zöchbauer <notifications@github.com

wrote:

@sgjesse https://github.com/sgjesse Thanks a lot for this quick
response!
Doesn't seem to add a lot of complexity.
What are the reasons for this changes being dropped?


Reply to this email directly or view it on GitHub
#21403 (comment).

@zoechi
Copy link
Contributor

zoechi commented Dec 11, 2015

I understand that reasoning, but it's sad to limit Darts usage on Unix systems this way because Windows doesn't provide anything similar :(

@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed triaged labels Mar 1, 2016
@Pajn
Copy link

Pajn commented Aug 5, 2016

Is there any development in this area?

There are many cross-platform languages that support Unix Sockets on platforms that have support for it and does not provide an alternative on Windows. The alternative already exist in the form of TCP and UDP, it's just a much worse alternative for certain use-cases.

Redis with Unix sockets can support around 50% more throughput than with TCP sockets, it's sad to have to think of that and have that as a thing to consider when choosing a server platform.

@bergwerf
Copy link

I want to attempt to write a very simple X11 client in Dart. Is Unix sockets really off the table? That would be quite sad in my opinion.

@zoechi
Copy link
Contributor

zoechi commented Jul 31, 2017

Another concern is to add platform specific APIs dart:io. If this should be
abstracted to also have a Windows counterpart we would have to find a
matching IPC concept on Windows, which would increase the complexity quite
a bit.

This missing feature prevents several use cases which don't apply to Windows, because they are not used much on Windows but are a significant limitation on Unix systems.

@bergwerf
Copy link

Perhaps there can be a dart:unix library for unix specific APIs?

@Hixie
Copy link
Contributor

Hixie commented Oct 8, 2017

FWIW, this is the workaround I used (to send the string status\n to a Unix domain socket named /tmp/control.socket):

await Process.run('/bin/sh', <String>['-c', 'echo status | nc -U /tmp/control.socket']);

@knopp
Copy link
Contributor

knopp commented Mar 3, 2018

Why not use named pipes as counterpart on Windows? While not being completely same thing, for example libuv has single pipe stream abstraction that works for both domain socket and named pipes. It is extremely useful for IPC.

@recoilme
Copy link

Is there any development in this area?

@roman-vanesyan
Copy link
Contributor

roman-vanesyan commented Jun 11, 2019

Other programming languages supports Unix sockets, despite the fact that support is only limited to Unix systems. For example, Rust marks API as "supported only on Unix". https://doc.rust-lang.org/std/os/unix/net/struct.UnixStream.html

Node.js also supports Unix sockets as well as Go.

Maybe the functionality can be exposed in specific module like dart:unix or dart:uds

@knopp
Copy link
Contributor

knopp commented Jun 11, 2019

NodeJS uses named pipes on windows (through libuv). We have a project using libuv on IPC (domain sockets on unix, named pipes on windows) and it works very well. I don't quite see why this couldn't be done for dart.

@ailabs-software
Copy link

Please fix this, this is the most annoying issue I have with Dart. I want to use Dart for IPC without management of clumsy ports.

@rahul-dutt-sharma
Copy link

rahul-dutt-sharma commented Jun 28, 2019

Just dropped my plan to use Flutter for my dream project cause of this

@ghost
Copy link

ghost commented Jul 3, 2019

We need that generally in future. For me not highest priority, but one of them, to Dart the world 👍

@radzish
Copy link

radzish commented Oct 20, 2019

I believe that without this it is not possible to write serverless Cloud Run service connecting to Google CloudSQL directly: https://cloud.google.com/sql/docs/mysql/connect-run, as last one requires connecting to DB through Unix Domain Sockets

@edwjusti
Copy link

edwjusti commented Jan 3, 2020

Windows supports AF_UNIX now. The dart runtime could simply throw an exception if support is not available. https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/

@roman-vanesyan
Copy link
Contributor

Seems that the work to integrate this was actually begun, see https://dart-review.googlesource.com/c/sdk/+/125932

@robert-ancell
Copy link
Contributor

Sending credentials using SCM_CREDENTIALS is a required feature for some Unix Domain Socket servers. I hope this can be integrated into the Dart API in some way.

@DrSensor
Copy link

DrSensor commented Feb 3, 2020

What about IOS/Mac?
Similiar on how nodejs/libuv switch to named pipes when running on Windows, does this feature need to switch to Mach port to avoid sandboxing restrictions?

@a-siva
Copy link
Contributor

a-siva commented Mar 17, 2020

flutter/flutter#44714 is blocked on this.

@a-siva
Copy link
Contributor

a-siva commented Mar 17, 2020

work on this is progressing here https://dart-review.googlesource.com/c/sdk/+/125932

@knopp
Copy link
Contributor

knopp commented Mar 17, 2020

@a-siva, any reason why named pipes can't be used on windows, just like in libuv/nodejs?

@a-siva
Copy link
Contributor

a-siva commented Mar 17, 2020

We will explore support on Windows after first getting this CL (Support on Linux, Macos and Android) to land.

dart-bot pushed a commit that referenced this issue Mar 23, 2020
Support Unix domain sockets communication on Linux, MacOS and Android.

Changes:
1. Add a field for InternetAddressType named unix.
2. Constructor of InternetAddress gains one more optional field: type. InternetAddress(String address, {InternetAddressType type});
3. Add another constructor to InternetAddress which taks raw address/path for ip/unix addresses as an argument. InternetAddress.fromRawAddress(Uint8List rawAddress, {InternetAddressType type});

The operation for unix domain sockets communication is basically the same as normal sockets except an InternetAddress with type unix should be passed.

Change-Id: I6a1135bbdd7f4e4fc745ccf8f95dec5272b6839b
Bug: #21403
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125932
Commit-Queue: Zichang Guo <zichangguo@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
@zichangg
Copy link
Contributor

The change has been landed. I open #41161 for supporting on Windows.

@banalg
Copy link

banalg commented Apr 14, 2020

Good news, but I didn't succeed creating a socket SOCK_SEQPACKET, requested for some services like uv4l.
Searching in the commit it seems we can only use SOCK_DGRAM and SOCK_STREAM.

Is it planned to accept others socket types ? http://man7.org/linux/man-pages/man2/socket.2.html

An example of how it's done in Golang : https://golang.org/src/net/unixsock_posix.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests