Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected "Connection closed" when runing with @wdio/cucumber-framework #115

Closed
seanpoulter opened this issue Feb 26, 2024 · 3 comments · Fixed by #116
Closed

Unexpected "Connection closed" when runing with @wdio/cucumber-framework #115

seanpoulter opened this issue Feb 26, 2024 · 3 comments · Fixed by #116

Comments

@seanpoulter
Copy link
Contributor

Problem

When I use @wdio/cucumber-framework to run my tests
Then I see an unexpected Error: Connection closed. Code: 1006

> wdio run ./test/wdio.conf.ts

Execution of 1 workers started at 2024-02-26T22:11:39.549Z

Skipping download, bundle for ChromeDriver v27.2.3 already exists
Found existing install in .../.wdio-vscode-service/vscode-linux-arm64-1.86.2. Skipping download

[0-0] RUNNING in chrome - file:///test/features/webview.feature
[0-0] file:///.../node_modules/wdio-vscode-service/src/service.ts:60
[0-0]         this._promisedSocket = Promise.reject(new Error(msg))
[0-0]                                               ^
[0-0] Error: Connection closed. Code: 1006, reason: 
[0-0]     at VSCodeWorkerService._handleSocketClose (file:///.../node_modules/wdio-vscode-service/src/service.ts:60:47)
[0-0]     at Object.onceWrapper (node:events:629:26)
[0-0]     at WebSocket.emit (node:events:526:35)
[0-0]     at WebSocket.emit (node:domain:488:12)
[0-0]     at WebSocket.emitClose (.../node_modules/wdio-vscode-service/node_modules/ws/lib/websocket.js:265:10)
[0-0]     at Socket.socketOnClose (.../node_modules/wdio-vscode-service/node_modules/ws/lib/websocket.js:1289:15)
[0-0]     at Socket.emit (node:events:514:28)
[0-0]     at Socket.emit (node:domain:488:12)
[0-0]     at TCP.<anonymous> (node:net:337:12)
[0-0] FAILED in chrome - file:///test/features/webview.feature

Spec Files:      0 passed, 1 failed, 1 total (100% completed) in 00:00:08  

Steps to Reproduce

I've reproduced the error from a private repo in https://github.com/seanpoulter/wdio-vscode-cucumber-example:

nvm install --lts
nvm use --lts
npm ci
npm run test

Analysis

The error is thrown from line 60

private _handleSocketClose (code: number, reason: Buffer) {
const msg = `Connection closed. Code: ${code}, reason: ${reason.toString()}`
this._promisedSocket = Promise.reject(new Error(msg))
this._pendingMessages.forEach((resolver) => resolver(msg, null))
}

which is registered on line 116

wss.on('connection', (socket) => {
log.info('Connected with VSCode workbench')
this._promisedSocket = Promise.resolve(socket)
resolve(socket)
clearTimeout(socketTimeout)
socket.on('message', this._handleIncoming.bind(this))
socket.once('close', this._handleSocketClose.bind(this))
})

Questions

  • Since this._promisedSocket is assigned in beforeSession hook, does it make sense to use the deleteSession hook to reset this._promisedSocket = undefined?
  • If this only affects Cucumber, does the solution belong there?
@christian-bromann
Copy link
Contributor

I wonder how the Cucumber execution differs from e.g. Mocha that causes this problem is the first place 🤔

@seanpoulter
Copy link
Contributor Author

Let me know if you want me to dig into it.

@christian-bromann
Copy link
Contributor

I think we can move forward with the patch #116 .. it's not to crucial for me to get to the bottom of this as long as we document what we are doing in #116 so everyone knows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants