neondatabase / neondatabase/serverless
`end()` uses non-null assertion `this.ws!.close()` but `ws` is `null` until async assignment — TypeError on early call
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 548
- Forks
- 81
- PR merge metrics
- No merged PRs in 30d
Description
Bug
In src/shims/net/index.ts around line 725, the end() method closes the WebSocket using a non-null assertion:
this.ws!.close();
However, this.ws is initialized to null and is only set asynchronously (in the Cloudflare fetch path, after the WebSocket upgrade completes). If end() is called before ws has been assigned — for example, when called with an empty buffer where the write callback fires immediately — this.ws is still null at that point and the ! operator produces a TypeError: Cannot read properties of null (reading 'close').
Issue #131 fixed the same class of null assertion in rawWrite() but end() was missed.
Reproduction
const socket = new NeonSocket(...);
socket.end(); // ws not yet assigned — TypeError: Cannot read properties of null
This also surfaces when end() is called during connection teardown before the WebSocket upgrade has resolved.
Fix
Guard against null before calling .close():
// Before
this.ws!.close();
// After
if (this.ws) {
this.ws.close();
}
This is consistent with the fix applied in #131 to rawWrite().
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/shims/net/index.ts around line 725 and compare end() with the null-handling fix in rawWrite() from issue #131. Verify the early end() reproduction and confirm that teardown before the WebSocket upgrade no longer raises a null close TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 86/100