{"record":{"id":"b4ff19d022013bf3","repo":"denoland/deno","slug":"sockets-cannot-be-copied","errorCode":null,"errorMessage":"sockets cannot be copied","messagePattern":"sockets cannot be copied","errorType":"exception","errorClass":"FsError","httpStatus":null,"severity":"error","filePath":"ext/fs/std_fs.rs","lineNumber":820,"sourceCode":"        .collect::<Result<Vec<_>, _>>()?;\n\n      return Ok(());\n    } else if ty.is_symlink() {\n      let from = std::fs::read_link(from)?;\n\n      #[cfg(unix)]\n      std::os::unix::fs::symlink(from, to)?;\n      #[cfg(windows)]\n      std::os::windows::fs::symlink_file(from, to)?;\n\n      return Ok(());\n    }\n    #[cfg(unix)]\n    {\n      use std::os::unix::fs::FileTypeExt;\n      if ty.is_socket() {\n        return Err(\n          io::Error::new(\n            io::ErrorKind::InvalidInput,\n            \"sockets cannot be copied\",\n          )\n          .into(),\n        );\n      }\n    }\n\n    // Ensure parent destination directory exists\n    if let Some(parent) = to.parent() {\n      fs::create_dir_all(parent)?;\n    }\n\n    copy_file(from, to)\n  }\n\n  #[cfg(target_os = \"macos\")]\n  {","sourceCodeStart":802,"sourceCodeEnd":838,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/fs/std_fs.rs#L802-L838","documentation":"In Deno's copy implementation, entries are classified by file type before copying; on Unix, an entry whose type is a socket (S_ISSOCK) is refused with io::ErrorKind::InvalidInput 'sockets cannot be copied' (ext/fs/std_fs.rs:820). An AF_UNIX socket is a live connection endpoint, not file content, so duplicating it has no meaning.","triggerScenarios":"Deno.copy() (recursive) over a directory containing socket files: /var/run or /run with docker.sock, postgres/.s.PGSQL.sock, redis.sock, systemd sockets; a project tree containing a dev-server socket.","commonSituations":"Backing up /run or /var/run; container image build scripts copying runtime directories; local dev trees with database or IPC sockets in them.","solutions":["Copy entries individually and skip those failing with 'sockets cannot be copied'","Exclude well-known socket names (*.sock) before copying","Use tar with --exclude for runtime directories instead of Deno.copy"],"exampleFix":"// before\nawait Deno.copy('/var/run/myapp', '/backup/myapp');\n\n// after\nawait Deno.mkdir('/backup/myapp', { recursive: true });\nfor (const entry of Deno.readDirSync('/var/run/myapp')) {\n  if (entry.name.endsWith('.sock')) continue;\n  await Deno.copy(`/var/run/myapp/${entry.name}`, `/backup/myapp/${entry.name}`);\n}","handlingStrategy":"try-catch","validationCode":"const looksLikeSocket = (name: string): boolean =>\n  name.endsWith('.sock') || name.endsWith('.socket');\n\nfor (const entry of Deno.readDirSync(srcDir)) {\n  if (looksLikeSocket(entry.name)) continue; // known runtime sockets\n  await Deno.copy(`${srcDir}/${entry.name}`, `${dstDir}/${entry.name}`);\n}","typeGuard":null,"tryCatchPattern":"for (const entry of Deno.readDirSync(srcDir)) {\n  try {\n    await Deno.copy(`${srcDir}/${entry.name}`, `${dstDir}/${entry.name}`);\n  } catch (e) {\n    if (e instanceof Error && /sockets cannot be copied/.test(e.message)) continue;\n    throw e;\n  }\n}","preventionTips":["Exclude *.sock / *.socket when copying runtime directories (/run, /var/run)","Use per-entry copies for directories that may contain IPC sockets","Prefer tar with --exclude for system directory backups"],"tags":["filesystem","copy","unix-socket","unsupported-file-type","deno"],"backgroundTag":"unsupported-file-type","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}