Node: net: socket file names are being truncated, and may become unremovable

Created on 14 Jun 2017  Â·  12Comments  Â·  Source: nodejs/node

  • Version: 7.9.0, 8.1.1
  • Platform: macOS, Linux
  • Subsystem: net

Ref: https://gist.github.com/stelcheck/78c35a0a691de1e25a3a413519cc3fcb

When using a string that's about over 100 characters length, the file name being created will be truncated until it no longer shows up when doing a simple ls - which also means it may no longer be removable by hand.

This does not happen when using relative paths, only when using long absolute paths (I haven't tested the case when using long relative paths, e.g. '../hello/../hello/../etc...').

libuv net

Most helpful comment

Fwiw, libuv v2 will fail with an error instead, but I’m not sure when that’s going to be released/included in Node.

All 12 comments

Just tested on Linux and this does not appear to be an issue there.

@addaleax @bnoordhuis is this to do with the 100 char socket length limit?

Refs: https://github.com/nodejs/node/issues/12708#issuecomment-297847882

Your path is > 100 characters long and might hit the BSD socket interface’s maximum length for UNIX socket paths…

Followon question, is this documented anywhere in node/libuv? I'd like to have something to refer people to if it comes up again.

If it's an issue that we have no choice but to accept, it would be good to throw an exception instead of truncating the path.

That is likely - although I seem to be able to create socket paths which are longer than 100 chars (maybe it doesn't include separators?).

The main issue is that the path is created, but potentially outside of the visible file system - so it can't be removed. So it would be a bit strange if underlying OS subsystems just decided to silently truncate in the case where there are limits...

Ah, according to documentation the limit would be 104 chars on mac.

https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man4/unix.4.html

According to this SO, Linux has a limit too (108 chars): https://unix.stackexchange.com/a/367012

I just took the example I have posted above, and increased the path length, and indeed, Linux is affected as well. Updating the issue summary.

Fwiw, libuv v2 will fail with an error instead, but I’m not sure when that’s going to be released/included in Node.

Got this error it in production on linux.

Socket path gets truncated to 107 chars, socket does not remove on restart, program crashes on startup with EADDRINUSE.

@addaleax Do you think we can do anything here? Document it for now perhaps?

It's documented in the synopsis of the net module:

### Identifying paths for IPC connections

...
On UNIX, the local domain is also known as the UNIX domain. The path is a
filesystem pathname. It gets truncated to `sizeof(sockaddr_un.sun_path) - 1`,
which varies on different operating system between 91 and 107 bytes.
The typical values are 107 on Linux and 103 on macOS.
...

Looks like there's nothing else to do so I'll close this out.

If libuv 2 won’t be happening in time for Node 11, we could decide to throw an error in Node.js instead, I guess.

I don't know if I'm in favor but I'm not opposed either.

Throwing an error would be the safest behavior in my opinion. I doubt everyone's first reflex will be to open the doc if they run in this issue, so a descriptive runtime would most likely help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

willnwhite picture willnwhite  Â·  3Comments

vsemozhetbyt picture vsemozhetbyt  Â·  3Comments

ksushilmaurya picture ksushilmaurya  Â·  3Comments

Brekmister picture Brekmister  Â·  3Comments

akdor1154 picture akdor1154  Â·  3Comments