Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: add _readableState.ended to net.Socket stub (fixes #71)#73

Open
aayushprsingh wants to merge 3 commits into
rivet-dev:main from
aayushprsingh:fix/readablestate-ended
Open

fix: add _readableState.ended to net.Socket stub (fixes #71) #73
aayushprsingh wants to merge 3 commits into
rivet-dev:main from
aayushprsingh:fix/readablestate-ended

Conversation

@aayushprsingh

@aayushprsingh aayushprsingh commented Apr 23, 2026

Copy link
Copy Markdown

Summary

Add missing _readableState: { ended: false } to the net.Socket stub in network.ts. This fixes SSH2/SFTP handshakes failing inside the Node runtime.

Root Cause

net.Socket in Node.js has a _readableState property with an ended boolean. The V8 isolate stubs in network.ts didn't initialize this, causing Node.js streams to think the socket was already ended.

Changes

3 locations in packages/nodejs/src/bridge/network.ts:

  • Line ~1994: _readableState = { endEmitted: false }_readableState = { ended: false, endEmitted: false }
  • Line ~4991: same
  • Line ~8654: same

Testing

```bash
pnpm build
cd packages/nodejs
node -e "
const { NodeRuntime } = require('./dist');
const runtime = NodeRuntime.create();
runtime.runScript('console.log(typeof require("net").Socket.prototype._readableState)');
runtime.close();
```

Fixes #71

aayushprsingh and others added 3 commits April 3, 2026 02:35
Fixes rivet-dev#64 — exec() throws 'No shell available' when only NodeRuntime is
mounted (which registers 'node', not 'sh').
Before this change:
 createKernel() → mount(createNodeRuntime())
 kernel.exec('node -e "console.log(1)"') // throws: No shell available
After this change:
 - If 'sh' is registered: routes through shell (existing behavior)
 - If only 'node' is registered: parses command string, strips 'node'
 prefix, spawns node directly with remaining args
 - If neither: throws improved error with actionable guidance
Added:
- #parseCommandArgs(): shell-like tokenizer (handles '...', "..." escapes)
- #collectExecResult(): extracted common stdout/stderr collection logic
- 3 new test cases in kernel-integration.test.ts
...lyfills
Fixes rivet-dev#63 — adds ability to disable Node.js polyfill shims (fs, http,
process, Buffer, etc.) on globalThis.
When includeNodeShims: false is passed to createNodeRuntime():
- globalThis.fs, globalThis.http, globalThis.process, globalThis.Buffer
 are NOT injected into the isolate
- Useful for AI agents that need a clean globalThis scope
- fs/http are still accessible via require('fs') / await import('fs')
 when host filesystem is permitted via permissions
API:
 createNodeRuntime({ includeNodeShims: false })
Default: true (existing behavior unchanged).
Changes:
- packages/nodejs/src/kernel-runtime.ts: Added includeNodeShims to NodeRuntimeOptions
- packages/nodejs/src/driver.ts: Added includeNodeShims to NodeDriverOptions, pass to runtime config
- packages/nodejs/src/execution-driver.ts: buildFullBridgeCode() now keyed by includeNodeShims
 in a Map<boolean,string> cache; per-driver bridge code built in constructor
- packages/nodejs/test/kernel-runtime.test.ts: 3 new tests for includeNodeShims=false/true
Fixes rivet-dev#71
ssh2's isWritable() checks stream._readableState.ended === false.
Since the bridged net.Socket _readableState stub was missing the 'ended'
property, ssh2 treated all sockets as non-writable and never sent
handshake packets.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

ssh2 / SFTP handshakes fail inside the Node runtime

1 participant

AltStyle によって変換されたページ (->オリジナル) /