jart / cosmopolitan

build-once run-anywhere c library
ISC License
17.28k stars 593 forks source link

Debian on WSL 2 Cannot Use redbean.com StoreAsset function #514

Open Alamantus opened 1 year ago

Alamantus commented 1 year ago

I'll start by apologizing if this is ignorant, but I'm trying to test StoreAsset in redbean.com using a Debian 9 install of WSL 2 on Windows 10, and every time I try to store a value using StoreAsset, the server log says StoreAsset() not available on Windows/NetBSD/OpenBSD yet even though it's running in what (I think) should be identified as Linux.

Am I misunderstanding the functionality? Or is WSL truly not actually Linux? Is there some way to force redbean.com to attempt storing the asset before denying the functionality based on the operating system?

Thanks for your awesome project!

pkulchenko commented 1 year ago

@Alamantus, I run redbean in a very similar configuration (Ubuntu instead of Debian) and don't see this happening. I do get StoreAsset call accepted, even though it fails later not able to acquire a write lock to update the file.

Also, what version of redbean are you running?

Alamantus commented 1 year ago

I tried it in WSL 1 with Ubuntu (a pre-existing install) with the same result but haven't tried it in Ubuntu on WSL 2 yet. I wonder if that would make a difference? Weird that it fails later for you though.

I'm pulling the redbean-latest.com as of yesterday, so presumably 2.0.15?

pkulchenko commented 1 year ago

Yes, redbean-latest.com should be 2.0.15. I just tried on my WSL2/Ubuntu config and running this ./redbean.com -e "StoreAsset('1', '1')" logs storing asset "1" and then errors out on can't getting a lock, but this message is after the one you're getting.

Alamantus commented 1 year ago

It's weird that I haven't seen anyone else having similar issues with this... Also while not immediately related to WSL, I want to note that on Ubuntu 22.04 (technically Pop!_OS), I am also getting the can't place write lock on file descriptor 3: EBADF error and the file is not writing when using StoreAsset.

thetanil commented 1 year ago

I had a similar issue on WSL because it's configured to handle windows binaries in Linux which is normally not the case. You can disable binfmt to fix it. I think this was the command to fix it, and it certainly has side effects on the way windows launches binaries under WSL, but it should work to get redbean to detect it is really running on linux.

echo -1 >/proc/sys/fs/binfmt_misc/status
pkulchenko commented 1 year ago

I am also getting the can't place write lock on file descriptor 3: EBADF error and the file is not writing when using StoreAsset.

@Alamantus, this issue has been fixed in the master branch. Maybe together with what @thetanil suggested the issue is going to be addressed for you? I think most of us compile redbean, so already have binfmt_misc fixed applied under WSL2, so we simply don't run into this issue.

Alamantus commented 1 year ago

I'll take a look and see if I can get it working from a self-compiled version.

bstro commented 1 year ago

I am encountering this same error on MacOS 11.6.7, redbean 2.2:

W2023-03-16T20:31:01+036653:tool/net/redbean.c:3631:wiki:47293] (srvr) can't place write lock on file descriptor 3: EBADF/9/Bad file number

Any ideas? Doesn't seem like a super common issue. I am trying to bundle a TiddlyWiki instance w/ Redbean following these instructions and using this .init.lua

pkulchenko commented 11 months ago

@bstro, @Alamantus, redbean added -* option that makes the executable modifiable if you need to call StoreAsset as part of some request handling logic. If you just need to add something to it, then -A option will do it (it doesn't require -*, as it will enable it internally).

jperon commented 9 months ago

I don’t know whether it’s related or another issue, but when running ./redbean.com --assimilate on Linux (NixOS in my case), I loose the ability to use StoreAsset with the same error message:

can't place write lock on file descriptor 3: EBADF/9/Bad file number

No such problem when using raw redbean.com.

pkulchenko commented 8 months ago

It's because with some of the recent changes it can't modify itself while it's running. You can try running it with -* option, but the current (master branch) version of redbean (temporarily) removed StoreAsset because of the issues with _OpenExecutable logic (see 5c9e03e3).