{"record":{"id":"ffd7c0c45d7f5367","repo":"n0-computer/iroh","slug":"selfconnect","errorCode":"SelfConnect","errorMessage":"Connecting to ourself is not supported","messagePattern":"Connecting to ourself is not supported","errorType":"error_code","errorClass":"ConnectWithOptsError","httpStatus":null,"severity":"error","filePath":"iroh/src/endpoint.rs","lineNumber":1122,"sourceCode":"        options: ConnectOptions,\n    ) -> Result<Connecting, ConnectWithOptsError> {\n        if self.is_closed() {\n            return Err(e!(ConnectWithOptsError::EndpointClosed));\n        }\n\n        let endpoint_addr: EndpointAddr = endpoint_addr.into();\n        let endpoint_id = endpoint_addr.id;\n\n        Span::current().record(\"remote\", tracing::field::display(endpoint_id.fmt_short()));\n\n        if let BeforeConnectOutcome::Reject =\n            self.inner.hooks.before_connect(&endpoint_addr, alpn).await\n        {\n            return Err(e!(ConnectWithOptsError::LocallyRejected));\n        }\n\n        // Connecting to ourselves is not supported.\n        ensure!(endpoint_id != self.id(), ConnectWithOptsError::SelfConnect);\n        ensure!(!alpn.is_empty(), ConnectWithOptsError::InvalidAlpn);\n\n        event!(\n            target: \"iroh::_events::conn::connecting\",\n            tracing::Level::DEBUG,\n            remote_id = %endpoint_id.fmt_short(),\n            alpn = %String::from_utf8_lossy(alpn),\n        );\n\n        debug!(\n            relay_url = ?endpoint_addr.relay_urls().next().cloned(),\n            ip_addresses = ?endpoint_addr.ip_addrs().cloned().collect::<Vec<_>>(),\n            \"connecting\",\n        );\n\n        let mapped_addr = self.inner.resolve_remote(endpoint_addr).await??;\n\n        let transport_config = options","sourceCodeStart":1104,"sourceCodeEnd":1140,"githubUrl":"https://github.com/n0-computer/iroh/blob/2b4de030ce5e0133f272871a76f0c685c63f552a/iroh/src/endpoint.rs#L1104-L1140","documentation":"An endpoint connection attempt targeted the endpoint's own EndpointId. A node cannot open a QUIC connection to itself through the same endpoint, so connect_with_opts rejects this immediately with ConnectWithOptsError::SelfConnect before any networking happens.","triggerScenarios":"Calling endpoint.connect(own_endpoint_id, alpn) (or passing an endpoint_addr whose endpoint_id equals self.id()) — e.g. dialing an address the node itself advertised, or a peer registry that returned this node's own entry.","commonSituations":"Bootstrapping nodes that add themselves to their peer list, tests reusing one endpoint for both sides, config files with a self-referencing relay/home address, discovering your own addresses via a discovery service and then dialing them.","solutions":["Filter out the local endpoint's own EndpointId before calling connect.","Compare the target against endpoint.id() and skip/self-handle those entries.","For loopback communication use an in-process channel instead of a QUIC connection.","In peer-discovery code, exclude the node's own advertised addresses from the dial list."],"exampleFix":"// before\nendpoint.connect(peer.endpoint_id, alpn).await?;\n// after\nif peer.endpoint_id != endpoint.id() {\n    endpoint.connect(peer.endpoint_id, alpn).await?;\n}","handlingStrategy":"validation","validationCode":"fn can_connect(ep: &Endpoint, target: EndpointId) -> bool { target != ep.id() }","typeGuard":"fn remote_id(ep: &Endpoint, id: EndpointId) -> Option<EndpointId> { (id != ep.id()).then_some(id) }","tryCatchPattern":"match endpoint.connect(id, alpn).await {\n    Err(e) if matches!(&e, ConnectWithOptsError::SelfConnect) => { /* skip self, not fatal */ }\n    other => other?,\n}","preventionTips":["Filter self entries out of peer lists and discovery results.","Never dial addresses your own node advertised.","In tests, use two separate endpoints for the two sides.","Keep a single source of truth for the local EndpointId."],"tags":["connection","self-connect","endpoint","p2p"],"backgroundTag":"unsupported-operation","analyzedSha":"2b4de030ce5e0133f272871a76f0c685c63f552a","analyzedAt":"2026-09-08T04:26:47.755Z","contentChangedAt":"2026-09-08T04:26:47.755Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}