Closed TommasoBendinelli closed 5 months ago
🤖
Hey there @TommasoBendinelli! Nice to see you diving into more adventures. What's cooking this time?
The error you're encountering, TypeError [ERR_INVALID_STATE]: Invalid state: Writer has been released
, is a Node.js error that typically occurs when you're trying to use a WritableStream that has already been released. This can happen if you're trying to write to the stream after it has been closed or ended.
In the context of your code, it seems like the error is being thrown when you're trying to fetch data from an API endpoint. The fetch
function is used to make HTTP requests and it returns a Promise that resolves to the Response to that request, whether it is successful or not.
The this._getHeaders()
function is likely used to get the necessary headers for the HTTP request. Without seeing the implementation of this function, it's hard to say for sure, but it's a common pattern in HTTP client libraries.
One possible reason for this error could be that the fetch operation is being performed after the stream (in this case, the HTTP response body) has already been consumed or cancelled. This could happen if you're trying to perform multiple operations on the same stream.
Here are a few things you could try to resolve this issue:
Ensure that you're not consuming the response body more than once. The body of a Response object is a Stream and can only be consumed once. If you're trying to read from it again after it's already been read, you'll get an error.
Check if you're cancelling the fetch operation before it has completed. If you're using an AbortController to cancel your fetch requests, make sure you're not calling abort()
before the request has completed.
If you're using any kind of stream manipulation libraries (like stream.pipeline or stream.finished), make sure you're handling them correctly. These libraries can sometimes release the underlying stream prematurely if not used correctly.
If none of these suggestions help, could you provide a bit more context about how and where you're using the fetch function? That would help in diagnosing the issue further.
I also think you have an issue here:
function parseOwnerRepoCommit(identifier) {
let ownerRepo = identifier;
let commit;
if (identifier.includes(":")) {
[ownerRepo, commit] = identifier.split(":", 1);
}
if (!ownerRepo.includes("/")) {
throw new Error(`Invalid identifier ${identifier}. Identifier must be in the format of 'owner/repo:commit' or 'owner/repo'.`);
}
const [owner, repo] = ownerRepo.split("/");
return [owner, repo, commit];
}
identifier.split(":", 1); -> Should be identifier.split(":", 2);
(Though this not solve the previous issue)
I also think you have an issue here:
function parseOwnerRepoCommit(identifier) { let ownerRepo = identifier; let commit; if (identifier.includes(":")) { [ownerRepo, commit] = identifier.split(":", 1); } if (!ownerRepo.includes("/")) { throw new Error(`Invalid identifier ${identifier}. Identifier must be in the format of 'owner/repo:commit' or 'owner/repo'.`); } const [owner, repo] = ownerRepo.split("/"); return [owner, repo, commit]; }
identifier.split(":", 1); -> Should be identifier.split(":", 2);
(Though this not solve the previous issue)
Hey, what version of langchainhub
are you on? The latest version 0.0.8
does do this.
@bracesproul Thanks for the reply. Yes you are right. I have upgrade langchain to latest, and this has been solved. However this: Exception has occurred: TypeError [ERR_INVALID_STATE]: Invalid state: Writer has been released is still being triggered. One workaround I found is to set global.fetch = require('node-fetch'). But I don't know whether is a proper solution
Hi, @TommasoBendinelli,
I'm helping the langchainjs team manage their backlog and am marking this issue as stale. From what I understand, you encountered a TypeError: Invalid state: Writer has been released error when making a fetch request. I provided a detailed response explaining potential causes of the error, and you also identified a separate issue in the code. Bracesproul mentioned an update in the langchainhub package, which seemed to resolve one of the issues. Additionally, you mentioned a workaround by setting global.fetch = require('node-fetch').
Could you please confirm if this issue is still relevant to the latest version of the langchainjs repository? If it is, please let the langchainjs team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.
Thank you for your understanding and cooperation. If you have any further questions or need assistance, feel free to reach out.
Hello I am getting the following error here:
const res = await fetch(
${this.apiUrl}/commits/${repoFullName}/?limit=${limit}&offset=${offset}
, { headers: this._getHeaders() }); (client.cjs)