testdriverai 7.3.18 → 7.3.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/agent/lib/sandbox.js +16 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/agent/lib/sandbox.js
CHANGED
|
@@ -71,7 +71,9 @@ const createSandbox = (emitter, analytics, sessionInstance) => {
|
|
|
71
71
|
let resolvePromise;
|
|
72
72
|
let rejectPromise;
|
|
73
73
|
|
|
74
|
-
if
|
|
74
|
+
// Check if socket exists and is actually open before sending
|
|
75
|
+
// This prevents sending to a closed connection (e.g., sandbox killed due to test failure)
|
|
76
|
+
if (this.socket && this.socket.readyState === WebSocket.OPEN) {
|
|
75
77
|
this.messageId++;
|
|
76
78
|
message.requestId = `${this.uniqueId}-${this.messageId}`;
|
|
77
79
|
|
|
@@ -150,8 +152,16 @@ const createSandbox = (emitter, analytics, sessionInstance) => {
|
|
|
150
152
|
return p;
|
|
151
153
|
}
|
|
152
154
|
|
|
153
|
-
// Return a rejected promise if socket is not available
|
|
154
|
-
|
|
155
|
+
// Return a rejected promise if socket is not available or not open
|
|
156
|
+
// This can happen when the sandbox is killed (e.g., due to test failure)
|
|
157
|
+
const state = this.socket?.readyState;
|
|
158
|
+
const stateMap = {
|
|
159
|
+
[WebSocket.CONNECTING]: "connecting",
|
|
160
|
+
[WebSocket.CLOSING]: "closing",
|
|
161
|
+
[WebSocket.CLOSED]: "closed",
|
|
162
|
+
};
|
|
163
|
+
const stateDesc = stateMap[state] || "unavailable";
|
|
164
|
+
return Promise.reject(new Error(`Sandbox socket not connected (state: ${stateDesc})`));
|
|
155
165
|
}
|
|
156
166
|
|
|
157
167
|
async auth(apiKey) {
|
|
@@ -355,6 +365,9 @@ const createSandbox = (emitter, analytics, sessionInstance) => {
|
|
|
355
365
|
this.socket.on("close", () => {
|
|
356
366
|
clearInterval(this.heartbeat);
|
|
357
367
|
this.apiSocketConnected = false;
|
|
368
|
+
// Also mark instance socket as disconnected to prevent sending messages
|
|
369
|
+
// to a closed connection (e.g., when sandbox is killed due to test failure)
|
|
370
|
+
this.instanceSocketConnected = false;
|
|
358
371
|
// Reset reconnecting flag so handleConnectionLoss can run for this new disconnection
|
|
359
372
|
this.reconnecting = false;
|
|
360
373
|
this.handleConnectionLoss();
|