cloudflare / cloudflare/workerd

🐛 Bug Report - Runtime API Connection Function Exception

Open
#4,497 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
8.7k
Forks
739
Avg merge
2d 20h
Merged PRs (30d)
174

Description

```js
// src/index.ts
import { connect } from "cloudflare:sockets";
var index_default = {
async fetch(req) {
const gopherAddr = { hostname: "gopher.floodgap.com", port: 70 };
const url = new URL(req.url);
try {
const socket = connect(gopherAddr);
const writer = socket.writable.getWriter();
const encoder = new TextEncoder();
const encoded = encoder.encode(url.pathname + "\r\n");
await writer.write(encoded);
await writer.close();
return new Response(socket.readable, { headers: { "Content-Type": "text/plain" } });
} catch (error) {
return new Response("Socket connection failed: " + error, { status: 500 });
}
}
};
export {
index_default as default
};
//# sourceMappingURL=index.js.map
```

Case code does not work
Socket connection failed: TypeError: This ReadableStream is disturbed (has already been read from), and cannot be used as a body.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.