Back

Appwrite runtime doesn't seem to support Stream, even though open-runtime does

  • 0
  • Self Hosted
  • Functions
grav
9 Jun, 2024, 19:25

Here's the function code, I kept it as small as possible: https://github.com/verydanny/hooks/blob/main/hooks/hello-world/src/main.js

I reproduced my code using open-runtime - node-21.0 and had no issues rendering content on the page, and no hangups. I did this because I thought the issue was with open-runtime somewhere.

When using Appwrite with node-21.0, it hangs indefinitely and shows the following error in the console:

TypeScript
openruntimes-executor              | 
openruntimes-executor              | Warning: Undefined array key "listening" in /usr/local/app/http.php on line 1023
openruntimes-executor              | 
openruntimes-executor              | Warning: fsockopen(): Unable to connect to 6666003e27327:3000 (Connection refused) in /usr/local/src/Executor/Validator/TCP.php on line 45
openruntimes-executor              | 
openruntimes-executor              | Warning: fsockopen(): Unable to connect to 6666003e27327:3000 (Connection refused) in /usr/local/src/Executor/Validator/TCP.php on line 45

I tracked the issue down to Readable.from(). Basically, with Appwrite, I can only send a Stream if it's a non-text MIME format, but as soon as it's JSON, HTML, or anything text-based it makes Appwrite hang forever.

This shouldn't be the case because html/txt should be streamable as well. I'm trying to build a mini router for functions, and it adds complexity and decreases performance if I have to check every file's MIME format and do response.text() for everything that's non-binary data.

Buffer.from works, but that would make the memory usage go up like crazy depending on the file being sent.

TL;DR
Developers are experiencing issues with Appwrite runtime not supporting Stream, unlike open-runtime. The problem seems to be related to the requirement of a `Content-Length` header, which shouldn't be necessary. An error message is shown when using Appwrite with `node-21.0`, leading to indefinite hangups. The issue is traced back to `Readable.from()`, where only non-text MIME formats can be sent as a Stream with Appwrite. Using `Buffer.from` works but can drastically increase memory usage. The ideal condition is for text-based MIME formats like HTML/txt to be streamable as well in Appwrite.
grav
9 Jun, 2024, 19:53

I think I tracked the issue to needing a Content-Length header, but this shouldn't be required. It seems to only be required in the appwrite context.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more