Actions2
- Message Actions
- Connection Actions
Connection → Close Connection
AI-generatedOverview
This node enables interaction with WebSocket streams within an n8n workflow. It supports operations on two main resources: Message and Connection. Specifically, for the Connection resource, it allows closing an active WebSocket connection.
A common use case is managing real-time data streams where you might want to programmatically close a WebSocket connection after certain conditions are met, such as completing data processing or handling errors gracefully.
For example, after receiving and processing messages from a WebSocket trigger node, you can use this node configured with the "Close Connection" operation to terminate the WebSocket connection cleanly.
Properties
| Name | Meaning |
|---|---|
| Websocket Resource Field (Parameter Name) | The name of the field in the incoming JSON that holds the WebSocket connection object. This must match the resource field name provided by the WebSocket trigger node (e.g., "ws"). |
Output
The node outputs an array of JSON objects, each representing the result of the operation for each input item. For the "Close Connection" operation, the output JSON includes:
success: A boolean indicating whether the close operation was successful (true).- The original WebSocket connection object under the key specified by the "Websocket Resource Field" property.
Example output JSON structure:
{
"success": true,
"ws": { /* original websocket connection object */ }
}
No binary data is produced by this node.
Dependencies
- Requires a WebSocket connection object passed into the node via the input data. This typically comes from a WebSocket trigger node.
- No external API keys or services are required.
- The node depends on the WebSocket connection object having a
.close()method to terminate the connection.
Troubleshooting
Error: "Execution error: No websocket resource received"
This occurs if the input data does not contain the expected WebSocket connection object under the specified resource field name.
Resolution: Ensure that the input JSON contains the WebSocket connection object and that the "Websocket Resource Field" property matches the field name used by the WebSocket trigger node.If the connection object does not have a
.close()method or is invalid, the node will throw an error.
Resolution: Verify that the input data is correctly passed from a WebSocket trigger node and that the connection object is intact.Using the node without proper input data or with mismatched resource field names will cause failures.
Links and References
- WebSocket API - MDN
- n8n documentation on WebSocket Trigger Node (for understanding how the WebSocket connection object is provided)