denoland/deno · error · SystemError
ERR_FS_CP_SOCKET
ERR_FS_CP_SOCKET
Error message
Cannot copy a socket file
What it means
During copy dispatch, if the source stat reports a socket, fs.cp rejects with CpError::Socket (kind 'SOCKET'), mapped by throwCpError to ERR_FS_CP_SOCKET ('Cannot copy a socket file', errno EINVAL). Unix domain sockets hold no persistent content — they are a rendezvous endpoint — so copying their directory entry is meaningless and refused.
Solutions
- Exclude socket entries: filter with fs.lstat + stats.isSocket() (or use glob exclude) before copying
- Clean the source tree of runtime sockets before archiving (sockets are recreated by their daemons)
- If you only need regular files, copy with a filter callback: { recursive: true, filter: (s) => !s.endsWith('.sock') }
Example fix
// before
fs.cp('/var/run/app', 'backup', { recursive: true }, cb); // hits a .sock file
// after
fs.cp('/var/run/app', 'backup', {
recursive: true,
filter: (src) => !fs.statSync(src).isSocket(),
}, cb); Defensive patterns
Strategy: validation
Validate before calling
const skipSockets = (src) => { const st = fs.lstatSync(src); return st.isDirectory() || st.isFile() || st.isSymbolicLink(); }; Type guard
const isCopyableEntry = (st) => st.isFile() || st.isDirectory() || st.isSymbolicLink();
Try / catch
try { await fs.promises.cp(src, dest, { recursive: true, filter: isCopyablePath }); } catch (e) { if (e.code === 'ERR_FS_CP_SOCKET') { /* exclude *.sock and retry once */ } else throw e; } Prevention
- Never recursive-copy /run, /var/run, or live daemon state dirs
- Use a filter that whitelists file kinds rather than blacklisting paths
- Sockets are recreated by daemons — just exclude them from backups
When it happens
Trigger: fs.cp on /run or /var/run trees (or any dir) containing *.sock files with { recursive: true }; containerizing a volume that includes a live database socket (postgres/.s.PGSQL.5432, docker.sock); archiving a node_modules/.cache directory that contains IPC sockets.
Common situations: Recursive backup/copy scripts sweeping system directories; CI copying a runtime state directory; Docker/K8v volume mirroring where daemons left sockets behind.
Related errors
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/d3bbd8e218fd4d64.
Report an issue: GitHub.
Appendix: source
Thrown at ext/node/polyfills/_fs/cp/cp.ts:100
});
case "EEXIST":
throw new ERR_FS_CP_EEXIST({
message: err.message,
path: err.path,
syscall: "cp",
errno: EEXIST,
code: "EEXIST",
});
case "EISDIR":
throw new ERR_FS_EISDIR({
message: err.message,
path: err.path,
syscall: "cp",
errno: EISDIR,
code: "EISDIR",
});
case "SOCKET":
throw new ERR_FS_CP_SOCKET({
message: err.message,
path: err.path,
syscall: "cp",
errno: EINVAL,
code: "EINVAL",
});
case "FIFO":
throw new ERR_FS_CP_FIFO_PIPE({
message: err.message,
path: err.path,
syscall: "cp",
errno: EINVAL,
code: "EINVAL",
});
case "UNKNOWN":
throw new ERR_FS_CP_UNKNOWN({
message: err.message,
path: err.path,View on GitHub (pinned to 9ad36f7a2c)