October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Fix Rsync “Connection Unexpectedly Closed” Errors

Rsync’s “connection unexpectedly closed” message means the remote protocol process disappeared—not one specific fault. Use the transport, timing, exit code, shell-output test, permissions, daemon logs, and timeout checks to isolate and fix it.
Length11 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

“Connection unexpectedly closed” means your local rsync lost its protocol connection to the remote rsync process. It is not a diagnosis of one specific fault. The remote process may never have started, a login shell may have written text into the protocol stream, a daemon may have rejected an option, a timeout may have ended an idle transfer, or the server process may have crashed or been killed. Identify the transport, capture the exit code, test the remote side independently, and then follow the matching branch below.

What the error actually means

Rsync uses a local process and a remote rsync process that exchange a binary protocol. The connection can use an SSH or other remote-shell command such as host:path, or a directly addressed rsync daemon such as host::module or rsync://. When the local process says the connection was unexpectedly closed, the other end of that protocol conversation has disappeared or become unusable.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The same event can be printed as rsync error: error in rsync protocol data stream (code 12), or as a broken-pipe write. Those messages identify a lost protocol conversation, not its root cause. A useful investigation therefore starts with the layer that failed rather than with a single presumed fix.

Start with a precise failure record

Before changing configuration, save the complete command and the exact output. A shortened command copied from a script can hide the option or transport that determines the troubleshooting path.

  • Copy the complete rsync command, including all options, the source, destination, and whether it runs from a script, scheduler, container, or interactive shell.
  • Record the local and remote rsync versions. Version differences matter particularly when a remote daemon parses options differently from a modern client.
  • Note when the disconnect occurs: before any transfer, during negotiation, after some files have copied, or after a long idle period.
  • Save the numeric exit code as well as the human-readable message. Codes 10, 12, 23, 30, and 35 point to different failure layers.
  • Write down whether the endpoint is an SSH/remote-shell target (host:path) or a daemon target (host::module or rsync://).

Do not infer a daemon problem from an SSH command or an SSH problem from a daemon URL. The two transports start the remote side differently and require different evidence.

Make remote diagnostics visible

A remote failure can be hidden inside the stream that rsync is using for file data. The Rsync Project recommends sending messages to standard error with --msgs2stderr -M--msgs2stderr where the installed versions support those options. The first option affects the local side; the -M form asks the remote rsync to use the same behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
rsync --msgs2stderr -M--msgs2stderr [your existing options] source host:path

Run the diagnostic form without removing unrelated options. If the remote process reports a missing executable, an access failure, or an option error on standard error, that message is more actionable than a generic protocol-stream error. If an older version rejects the diagnostic option, repeat the test without it and rely on the transport-specific checks below.

When the command uses SSH or another remote shell

An SSH-style command normally causes the local rsync to start a remote shell, which in turn starts rsync on the other host. The remote shell must be quiet and must successfully execute the requested rsync command.

1. Test the shell without rsync

Use the same host and account that the transfer uses:

ssh remotehost /bin/true > out.dat

If the remote shell is functioning correctly, out.dat should have zero length. Check it directly:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
wc -c < out.dat

A non-empty file is strong evidence that something in the non-interactive login path printed text. Typical sources include .profile, .cshrc, or another startup script. A banner, diagnostic echo, command-not-found message, or other text arrives where rsync expects protocol bytes and can cause code 12 or a broken pipe.

Remove or conditionally suppress that output for non-interactive sessions. Keep normal prompts and human-facing messages for interactive shells, but ensure a non-interactive SSH invocation used by automation emits nothing unless the command itself writes output. Repeat the /bin/true test until the redirected file is empty, then retry rsync.

2. Verify that the remote rsync can start

Use the same account and host to check the executable and its search path. A shell that connects successfully can still fail when it cannot find or execute rsync.

ssh remotehost 'command -v rsync'
ssh remotehost 'rsync --version'

If the account has a restricted PATH, the interactive shell may find rsync while the non-interactive shell cannot. Use the absolute rsync path in the remote command or correct the account’s non-interactive environment, according to the server’s policy. The local and remote versions should both be recorded before changing anything; a version mismatch is not automatically an error, but it is important context when an option is rejected.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Also confirm that the account is permitted to run rsync. Forced commands, restricted shells, service accounts, and policy tools can accept an SSH connection while refusing the requested program. The refusal may be printed by the shell or policy layer and then appear locally as a protocol failure.

3. Check the path and permissions separately

Test the source and destination with the same account outside the transfer. The remote process can exit immediately if it cannot read the source, create the destination, traverse a parent directory, or access a required filesystem.

ssh remotehost 'test -r /path/to/source'
ssh remotehost 'test -x /path/to/destination-parent'
ssh remotehost 'test -w /path/to/destination'

Replace the paths with the actual locations and interpret a nonzero result as a permissions or path problem to fix before rerunning rsync. A destination can exist but still be unusable because the account lacks write permission or search permission on a parent directory. For a source, read permission on the file is not enough if the account cannot traverse the directory tree.

4. Look for shell output introduced by a command wrapper

Some deployments invoke rsync through a wrapper, a login shell option, or a remote command configured in SSH. Any wrapper must execute rsync and remain silent. Log messages, environment dumps, debugging echo commands, and error text on standard output corrupt the protocol just as a profile banner does. Redirect intentional diagnostics to standard error, and make sure a successful startup does not print a heading or status line.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When the command uses an rsync daemon

Daemon connections use host::module or rsync:// rather than starting rsync through SSH. The daemon itself accepts the connection, selects a module, validates options and access controls, and then serves or receives data.

Inspect the daemon log first

For a daemon failure, the server log is usually more informative than the client’s “connection unexpectedly closed” line. Look for:

  • an option the daemon refused or could not parse;
  • a module configured as read-only when the operation attempts to write;
  • an access-control, authentication, or host-allow/deny decision;
  • a missing or inaccessible module path;
  • an immediate daemon exit, crash, or resource failure.

Older daemon versions could hide option errors from clients, leaving only a generic disconnect on the local side. If the log shows that behavior and the daemon is obsolete, upgrading it is a remediation to evaluate after confirming compatibility with the server configuration and client versions.

Separate network reachability from module authorization

A connection that reaches the daemon is not proof that the requested module is usable. Test the exact daemon endpoint and module, then compare the result with the daemon log. A refused module, a read-only setting, or an access rule can close the session during negotiation, before any file data is transferred.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not apply SSH startup-file changes to a daemon-only failure: no remote login shell is involved in that path. Conversely, a clean daemon log does not prove that an SSH remote shell is clean.

Use timing to choose the next test

The point at which the connection closes narrows the likely layer. Treat timing as a branch point, not as proof of a single cause.

Failure timing Likely layer to inspect Next evidence
Before any bytes or immediately after connection Remote command startup, shell output, executable availability, daemon authorization, or option parsing Run the independent SSH test, verify remote rsync, or inspect the daemon log
During negotiation Protocol corruption, rejected options, incompatible or obsolete daemon behavior, or a remote process that exits Enable diagnostic messages, record both versions, and check server-side logs
After some files have transferred Permission or storage error, process termination, network interruption, or resource limit Check the remote process and system logs, filesystem state, and the exact exit code
After a long lull Idle connection closure or an unsuitable timeout Review --timeout, link and firewall idle policies, and keep-alive behavior

Interpret the rsync exit code

The numeric code identifies the layer that reported failure, but it does not by itself identify the underlying cause. Use it to select evidence rather than to skip the transport checks.

Code Meaning What to investigate
10 Socket I/O error Network interruption, socket failure, or the peer disappearing at the transport layer
12 Error in the rsync protocol data stream Remote process exit, shell output contaminating the stream, rejected startup, or another protocol-level interruption
23 Partial transfer due to error Which files failed, their permissions and paths, and whether the remote process or storage failed after the transfer began
30 Timeout in data send/receive Idle or stalled data transfer and the value of --timeout relative to the workload and link
35 Timeout waiting for a daemon connection Daemon reachability, listener state, network path, and connection-timeout settings

A code 12 accompanied by a non-empty out.dat points strongly toward shell startup output, while code 30 or 35 directs attention to timeout behavior. A code 23 requires examining the partial-transfer details rather than assuming the connection itself was the only problem.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Fix idle connections and broken-pipe symptoms

An apparently healthy link can still lose an rsync session if no data crosses it for long enough. Firewalls, proxies, NAT devices, or the peer may close an idle connection. The rsync project notes that newer versions can send keep-alive messages during lulls; behavior depends on the versions and options in use.

Set a suitable --timeout for the network and workload:

rsync --timeout=SECONDS [your existing options] source host:path

Choose a value that exceeds the longest expected pause while still detecting a genuinely stalled transfer. A very short value can terminate a slow but valid operation; an excessively long value delays detection and recovery. Code 30 indicates a timeout while sending or receiving data, whereas code 35 indicates that a daemon connection was not established in time. Those are different stages and should not be treated interchangeably.

A “broken pipe” write generally means the local side attempted to write after the other process or network path had closed. Check why the peer exited first: shell contamination, a daemon refusal, a remote crash, or a timeout. Increasing a timeout without finding an immediate remote exit will not repair the protocol.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Investigate a remote process that exits or crashes

If the SSH startup test is clean, the remote executable exists, permissions are correct, and the daemon log does not show a normal refusal, inspect the server at the moment of failure.

  • Review operating-system logs for an out-of-memory kill, process termination, service restart, or kernel-level storage error.
  • Check memory pressure, process and file-descriptor limits, CPU or cgroup limits, and available filesystem space.
  • Inspect the rsync daemon log if the daemon process is involved.
  • Look for read errors, failing storage, or a destination filesystem that has become unavailable.
  • Compare the time of the local disconnect with the server’s event timestamps.

When a daemon-side crash must be isolated, the Rsync Project’s troubleshooting guidance recommends running the daemon in the foreground with tracing. Use that mode only in a controlled maintenance window or a dedicated test instance, because foreground operation and verbose tracing can change service behavior and produce substantial logs. The trace should show whether the daemon exits while parsing options, opening a module, reading a file, or transferring data.

A complete recovery sequence

Use this ordered procedure when the cause is not obvious. Stop at the first step that produces a concrete fault, fix that fault, and then repeat the original transfer.

  1. Save the exact invocation. Include the full command, both rsync versions, transport form, exit code, and the point at which the disconnect occurs.
  2. Expose diagnostics. Add --msgs2stderr -M--msgs2stderr where supported and preserve the resulting standard-error output.
  3. Choose the transport branch. Use the SSH checks for host:path; use daemon logs and module checks for host::module or rsync://.
  4. For SSH, run the zero-output test. Execute ssh remotehost /bin/true > out.dat with the same account and verify that the file is empty.
  5. For SSH, verify startup. Confirm that the account can locate and execute rsync, that any wrapper is silent, and that the source or destination path is accessible.
  6. For a daemon, inspect server evidence. Check option parsing, module mode, access rules, path availability, and whether the daemon exited.
  7. Classify the exit code. Use codes 10, 12, 23, 30, and 35 to select socket, protocol, partial-transfer, data-timeout, or daemon-connection evidence.
  8. Check idle behavior. If the failure follows a lull, set a workload-appropriate --timeout and account for keep-alive support in the installed versions.
  9. Inspect the server for unexplained termination. Correlate system and daemon logs with the client timestamp; use a foreground traced daemon for a reproducible daemon crash.
  10. Retry the smallest safe transfer. Once the fault is corrected, test a limited source or destination first, then run the full job. Keep the successful command and diagnostic output with the job documentation.

Common wrong turns

Assuming every code 12 is a network outage

Code 12 names a protocol data-stream error. A login shell that prints one line can produce it even when SSH networking is perfect. Run the redirected /bin/true test before changing routes, keys, or firewall rules.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Testing with a different account or host

Shell startup files, PATH values, permissions, forced commands, and module access are account-specific. A successful test from an administrator account does not validate the service account used by the failing job.

Changing timeout values for an immediate disconnect

A timeout cannot fix a remote command that exits during startup or a daemon that rejects an option. First determine whether the failure occurs before data transfer or only after an idle interval.

Ignoring the server because the client printed an error

The client can only report that its peer vanished. When the remote process is killed, crashes, or refuses a module, the decisive evidence is in the remote system or daemon logs.

Leaving diagnostic output enabled without checking its destination

Diagnostics should go to standard error, not into the protocol data stream. After troubleshooting, review scripts and wrappers so temporary output does not become a permanent source of corruption or noisy logs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Prevent the error from returning

  • Keep non-interactive shell startup silent and test it after profile changes.
  • Document the absolute path to rsync when service accounts have restricted environments.
  • Record the local and remote versions alongside the transfer configuration.
  • Keep daemon configuration, module permissions, and access rules under change control.
  • Set --timeout based on measured pauses and the network’s idle policies rather than copying an arbitrary value.
  • Monitor server memory, storage, process limits, and daemon restarts for scheduled transfers.
  • Retain the complete command and exit code in job logs so a future failure can be classified immediately.

The practical distinction is simple: SSH transfers require a silent, executable remote shell command; daemon transfers require a healthy, authorized daemon and module. In both cases, the local message only tells you that the protocol peer is gone. The transport, timing, exit code, and server evidence tell you why.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.