Open ReneWerner87 opened 3 years ago
Thanks for opening your first issue here! ๐ Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord
$shell: docker run --rm -p 3000:3000 -it -v ${PWD}:/usr/app/src -w /usr/app/src golang:alpine sh
The same code base works in the linux container, i.e. it should be a problem specific to the operating system.
Thank you for creating my issue
@ReneWerner87 I have macOS, do you need help? Can I investigate too?
@ReneWerner87 I have macOS, do you need help? Can I investigate too?
Really appreciate it if you can help!
I don't know if it is related, but on my AWS Linux server I get
panic: listen tcp :6443: bind: address already in use
when Prefork is set to true.
If Prefork is set to false, it runs perfectly fine.
I built the app with Fiber 2.7.1 .
The exception is triggered on the line
ln, err := tls.Listen("tcp", fmt.Sprintf(":%v", models.SKFRONTWS_Port), tlsCfg)
The app is run with sudo
for testing.
Interestingly enough, same binary will accept to run with Prefork set to true on my Linux laptop.
Should not be related
This means opening a separate issue, right ?
Depends on whether you take the adapter package, then you make there an issue on
The error message says in any case, that somehow the port is already occupied, you must look at your implemtation, maybe this is not possible in the aws
preforkServer.Reuseport = true
makes fasthttp
demo get the same issue.
pls check https://github.com/kavu/go_reuseport
Is there any update on this?
Sorry everyone, I never looked at this issue again. Are there any updates?
@ReneWerner87 this still seems to be an issue, I'll have a look this week and see if I can fix:
~/prefork ยป go run main.go sixcolors@Jason-McNeils-Mac-Pro
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Fiber v2.52.0 โ โ Child PIDs ... 80628, 80629, 80630, 80631, 80632 โ
โ http://127.0.0.1:3000 โ โ 80633, 80634, 80635, 80636, 80637, 80638, 80639 โ
โ (bound on host 0.0.0.0 and port 3000) โ โ 80640, 80641, 80642, 80643, 80644, 80645, 80646 โ
โ โ โ 80647, 80648, 80649, 80650, 80651 โ
โ Handlers ............. 2 Processes .......... 24 โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Prefork ........ Enabled PID ............. 80627 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
ProcessId: 80628, 80627, isChild: true ProcessId: 80628, 80627, isChild: true ProcessId: 80628, 80627, isChild: true ProcessId: 80628, 80627, isChild: true ProcessId: 80628, 80627, isChild: true ProcessId: 80628, 80627, isChild: true ProcessId: 80628, 80627, isChild: true ProcessId: 80628, 80627, isChild: true ProcessId: 80628, 80627, isChild: true
Preliminary investigation: Fasthttp prefork.go Reuseport = false
by default (except on windows, where it must be true). If Reuseport = true
we get the same results in fasthttp example from description:
~/prefork ยป go run fast.go sixcolors@Jason-McNeils-Mac-Pro
ProcessId: 81649, 81648, isChild: true ProcessId: 81649, 81648, isChild: true ProcessId: 81649, 81648, isChild: true ProcessId: 81649, 81648, isChild: true ProcessId: 81649, 81648, isChild: true ProcessId: 81649, 81648, isChild: true ProcessId: 81649, 81648, isChild: true ProcessId: 81649, 81648, isChild: true ProcessId: 81649, 81648, isChild: true ProcessId: 81649, 81648, isChild: true ProcessId: 81649, 81648, isChild: true ProcessId: 81649, 81648, isChild: true ProcessId: 81649, 81648, isChild: true
This is due to the differences in how macOS and Linux handle the SO_REUSEPORT
socket option. On Linux, the kernel will evenly distribute incoming connections among all the processes listening on the same port. However, on macOS, the kernel will not distribute the connections, which results in one process (in this case, the first child process) handling all the connections. See https://stackoverflow.com/questions/14388706/how-do-so-reuseaddr-and-so-reuseport-differ
Fasthttp uses a file Listener when Reuseport = false
, so that's why it's working.
I am unsure about using a file listener-based approach on macOS. I thought a lightweight load balancer that uses ports greater than 1024 might be a better option. What do you think?
Sounds good
Fiber version v2.5.0
OS Systemversion: macOS 11.2.1 (20D74) Kernel-Version: Darwin 20.3.0
Issue description In the prefork concept, one child process is started for each cpu core and the work of the handlers is divided between these processes, so when you output the process number of the child process in the handler, different ids should appear, which is not the case here.
The goal of the ticket is to check where the problem is, because with fasthttp it works.
Code snippet
Output:
Working Fasthttp example:
Output: