spacedriveapp/spacedrive · error · anyhow::Error

Failed to finish stream: {}

Error message

Failed to finish stream: {}

What it means

send.finish() on the unidirectional stream failed because the stream was already closed or reset - typically the peer reset the stream before consuming the message. For fire-and-forget sends this mostly means the peer rejected or dropped the stream early.

Source

Thrown at core/src/service/network/transports/sync.rs:146

		// Write length prefix (required by multiplexer)
		let len = bytes.len() as u32;
		send.write_all(&len.to_be_bytes())
			.await
			.map_err(|e| anyhow::anyhow!("Failed to write length prefix: {}", e))?;

		// Write message bytes
		send.write_all(&bytes).await.map_err(|e| {
			warn!(
				device_uuid = %target_device,
				error = %e,
				"Failed to write sync message to stream"
			);
			anyhow::anyhow!("Failed to write message: {}", e)
		})?;

		send.finish()
			.map_err(|e| anyhow::anyhow!("Failed to finish stream: {}", e))?;

		tracing::info!(
			"Sync message sent successfully to device {} ({} bytes via uni stream)",
			target_device,
			bytes.len()
		);

		Ok(())
	}

	/// Send a sync request and wait for response
	///
	/// Uses bidirectional streams for proper request/response pattern (Iroh best practice)
	async fn send_sync_request(
		&self,
		target_device: Uuid,
		request: SyncMessage,
	) -> Result<SyncMessage> {

View on GitHub (pinned to 6dfeccf211)

Solutions

  1. Inspect peer logs for the reset reason
  2. Reconnect and resend once
  3. Verify protocol version compatibility for the message type being sent
Defensive patterns

Strategy: try-catch

Type guard

fn is_finish_failure(err: &anyhow::Error) -> bool {
    err.to_string().contains("Failed to finish stream")
}

Try / catch

if let Err(e) = net.send_sync_message(device, msg).await {
    if is_finish_failure(&e) {
        // peer reset the stream early; check peer logs before resending,
        // since the message may already have been consumed
    }
}

Prevention

When it happens

Trigger: Peer reset the uni stream on receipt (shutdown, unknown message, handler gone); connection lost between the body write and finish; finishing an already-finished stream.

Common situations: Peer app closing during sync; peer version that resets streams for unknown message types.

Related errors


AI-assisted analysis of spacedriveapp/spacedrive@6dfeccf211 (2026-08-16). Data as JSON: /api/errors/8ffdbe83a933e715. Report an issue: GitHub.