v icon indicating copy to clipboard operation
v copied to clipboard

vweb: host 0.0.0.0 breaks with -prod and flags

Open esquerbatua opened this issue 1 year ago • 10 comments

Describe the bug

Gives this error: V panic: failed to listen 0 net: socket error: 9; code: 9; binding to 0.0.0.0:8080 failed v hash: 6b3449b

Reproduction Steps

Run vweb with 0.0.0.0 as host and a port, with this flags: v -prod -d no_segfault_handler . or v -prod -cflags "-static" .

module main

import vweb

struct App {
	vweb.Context
}

fn main() {
	vweb.run_at(&App{}, vweb.RunParams{
		host: '0.0.0.0'
		port: 8080
		family: .ip
	}) or { panic(err) }
}

Expected Behavior

Run as dev builds: '[Vweb] Running app on http://0.0.0.0:8080/'

Current Behavior

V panic: failed to listen 0 net: socket error: 9; code: 9; binding to 0.0.0.0:8080 failed v hash: 6b3449b

Possible Solution

No response

Additional Information/Context

No response

V version

latest (0.4.3 6b3449b)

Environment details (OS name and version, etc.)

OS: linux, Ubuntu 22.04.3 LTS Processor: 64bit, little endian CC version: cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

[!NOTE] You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote. Other reactions and those to comments will not be taken into account.

esquerbatua avatar Jan 08 '24 15:01 esquerbatua

Also fails when you put 127.0.0.1, maybe with another values also fails

esquerbatua avatar Jan 08 '24 15:01 esquerbatua

It didn't reproduce, but I tested it on MacOS. Are you sure your port 8080 is free?

shove70 avatar Jan 09 '24 04:01 shove70

Yes, it's free, I tested also inside a docker with the image alpine:latest, and also fails

FROM thevlang/vlang:alpine-dev AS builder

WORKDIR /app
RUN v up
COPY . .
RUN v -prod -cflags "-static" -o test .

FROM alpine:latest

WORKDIR /app

COPY --from=builder /app/test ./

EXPOSE 8080

ENTRYPOINT [ "./test" ]

I have not tested the example, but with a vweb version with more code it's failing with the same error

esquerbatua avatar Jan 09 '24 08:01 esquerbatua

That's a bit weird. I tested it on rockylinux and it passed...

shove70 avatar Jan 09 '24 10:01 shove70

Yep, now in ubuntu fails, but in alpine it's working (with more flags), but in that PR it's failing, not with the same error code but: https://github.com/vlang/v/pull/20448 action: https://github.com/vlang/v/actions/runs/7459400961/job/20295324077?pr=20448

esquerbatua avatar Jan 09 '24 11:01 esquerbatua

If you consistently can get a failed PR there should be a precise repro. The code you posted here seems to work fine for us, under the conditions you provided.

PS. you quoted two different socket error codes - is it 99 or 9? In the PR it's 99.

#define	EADDRNOTAVAIL	99	/* Cannot assign requested address */
#define EBADF            9      /* Bad file number */

hholst80 avatar Jan 10 '24 23:01 hholst80

@hholst80 I'm getting the two errors, in different systems, I'm going to try to get an example to repoduce it. They are both errors, 9 and 99.

esquerbatua avatar Jan 12 '24 14:01 esquerbatua

Maybe the problem occurs when it's only available ipv4, when try to bind to ipv6 and it's not available it's failing

esquerbatua avatar Jan 15 '24 13:01 esquerbatua

It seems that now it's working as spected.

esquerbatua avatar Jan 29 '24 09:01 esquerbatua

It's failing again, I can't reproduce in local

esquerbatua avatar Mar 04 '24 10:03 esquerbatua

With the alpine image of vlang when building it, if you use this:

RUN echo "net.ipv6.conf.all.disable_ipv6 = 1" > /etc/sysctl.d/01-disable-ipv6.conf
CMD ["sysctl", "-p", "/etc/sysctl.d/01-disable-ipv6.conf"]

It disables ipv6 and it work as spected

esquerbatua avatar Aug 16 '24 16:08 esquerbatua

@esquerbatua so it fails still if IPv6 is enabled?

hholst80 avatar Sep 06 '24 14:09 hholst80

@esquerbatua so it fails still if IPv6 is enabled?

Now I'm not sure, but disabling ipv6 inside the container never failed again

esquerbatua avatar Sep 06 '24 14:09 esquerbatua