{"record":{"id":"00086a5d0b194134","repo":"swc-project/swc","slug":"failed-to-unwrap-arc-other-references-to-transfor","errorCode":null,"errorMessage":"Failed to unwrap Arc: other references to transform_result exist","messagePattern":"Failed to unwrap Arc: other references to transform_result exist","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/swc_plugin_runner/src/transform_executor.rs","lineNumber":81,"sourceCode":"        let returned_ptr_result = self.instance.transform(\n            guest_program_ptr.0,\n            guest_program_ptr.1,\n            unresolved_mark.as_u32(),\n            should_enable_comments_proxy,\n        )?;\n\n        self.instance\n            .caller()?\n            .free(guest_program_ptr.0, guest_program_ptr.1)?;\n        self.instance.cleanup()?;\n\n        // Construct serialized struct from raw bytes.\n        // Since we have finished transformation, it's safe to fetch the data from\n        // Arc<Mutex<T>>\n        drop(self.instance);\n        let transformed_result = Arc::try_unwrap(self.transform_result)\n            .map_err(|_| {\n                anyhow!(\"Failed to unwrap Arc: other references to transform_result exist\")\n            })?\n            .into_inner();\n        let ret = PluginSerializedBytes::from_bytes(transformed_result);\n\n        let ret = if returned_ptr_result == 0 {\n            Ok(ret)\n        } else {\n            let err: PluginError = ret.deserialize()?.into_inner();\n            match err {\n                PluginError::SizeInteropFailure(msg) => Err(anyhow!(\n                    \"Failed to convert pointer size to calculate: {msg}\"\n                )),\n                PluginError::Deserialize(msg) | PluginError::Serialize(msg) => {\n                    Err(anyhow!(\"{msg}\"))\n                }\n                _ => Err(anyhow!(\n                    \"Unexpected error occurred while running plugin transform\"\n                )),","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/swc-project/swc/blob/d7d74346665e36e692aa07e13d4ee3ee692ee35c/crates/swc_plugin_runner/src/transform_executor.rs#L63-L99","documentation":"Internal invariant failure in the plugin transform executor: after the plugin instance is dropped, the result buffer Arc<Mutex<Vec<u8>>> (shared with the plugin's host environment so set_transform_result can write into it) must have exactly one reference. Arc::try_unwrap failing means some component - the runtime's imported-function environment, a leaked instance handle, or a concurrent use of the same executor state - still holds a clone, so the transformed bytes cannot be safely extracted.","triggerScenarios":"A custom runtime implementation that keeps function-environment references alive after instance drop, reusing/sharing TransformExecutor state across concurrent transforms, or a bug in plugin instance teardown. Not triggerable by malformed user input alone.","commonSituations":"Embedding swc_plugin_runner with a custom Runtime/Instance implementation that retains host environments; swc version regressions in teardown ordering; rarely, invoking the same plugin transform concurrently through one cached instance.","solutions":["Upgrade swc/swc_core to the latest patch - teardown ordering bugs here get fixed quickly","If you implement a custom runtime, verify your Instance drops all imported function environments (including the set_transform_result host env) so the Arc refcount reaches 1","Avoid sharing one executor/instance across concurrent transforms; instantiate per task","If it persists with the stock runtime, capture versions (swc_core, wasmer runtime) and report upstream"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Rust: this is an internal invariant failure - catch, log, and surface versions\nmatch executor.run(...) {\n    Err(e) if e.to_string().contains(\"other references to transform_result exist\") => {\n        tracing::error!(\"swc plugin teardown bug; swc_core={}, report upstream\", env!(\"CARGO_PKG_VERSION\"));\n        return Err(e);\n    }\n    other => other,\n}","preventionTips":["Pin exact swc_core versions and update deliberately; teardown fixes ride patch releases","Custom Runtime implementors: drop all imported-function environments when the instance drops","Never share one plugin instance/executor across concurrent transform tasks"],"tags":["swc","plugins","wasm","internal","arc","concurrency"],"backgroundTag":null,"analyzedSha":"d7d74346665e36e692aa07e13d4ee3ee692ee35c","analyzedAt":"2026-08-16T12:41:13.160Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}