v icon indicating copy to clipboard operation
v copied to clipboard

veb, server drops connection, error parsing request

Open timurgordon opened this issue 1 year ago • 6 comments

Describe the bug

Sometimes, the server drops connection after certain requests, logging [veb] error parsing request: io.Eof:. This is a difficult bug to isolate, as it happens almost randomly. A few refreshes and sometimes the request works again. Sometimes switching browsers works, until it doesn't. More so this is observed with post requests. The bug is experienced with different browser clients (tried with Firefox and Safari), and server running both in linux and macOS.

Reproduction Steps

Run the following, try submitting the register form on different tabs, browsers, until the server hangs up. Sometimes it doesnt happen in a streak, sometimes it happens and lingers.

module main

import veb

pub struct App {}

pub struct Context {
	veb.Context
}

pub fn new() !&App {
	mut app := &App{}
	return app
}

pub fn run() ! {
	mut app := new()!
	veb.run[App, Context](mut app, 8090)
}

pub fn (app &App) index(mut ctx Context) veb.Result {
	return ctx.html('
<!DOCTYPE html>
<html lang="en" data-theme="light">
<body>
    <main>
        <h2>Login</h2>
        <form action="/register" method="POST">
            <label for="email">
                Use your Email to Register or Login.
                <input type="email" id="email" name="email" placeholder="Enter your email" required>
            </label>
            <button type="submit">Log In</button>
        </form>
    </main>
</body>
</html>	
')
}

@[post; '/register']
pub fn (mut app App) register(mut ctx Context) veb.Result {
	return ctx.text('authentication mail sent')
}

pub fn main() {
	run() or {panic(err)}
}

Expected Behavior

For the server to be able to parse the request. If not, for the server to allow the developer to handle the error instead of spontaneously dropping connection. Consistency in behavior and error occurrence under the same conditions.

Current Behavior

veb error when parsing incoming request, being thrown seemingly randomly.

[veb] error parsing request: io.Eof:

Possible Solution

Could be a memory problem due to the random nature of the occurrences of the error. The buffered reader may have memory issues because the size of the buffer to read and parse the incoming request is set correctly, and the request is formatted correctly with the correct length header, so there shouldn't be an unexpected end of file. Or maybe a picoev error?

Additional Information/Context

Not sure if it helps but the error seems to occur more in safari than Firefox, and in post requests more so than get. Nevertheless it happens on both browsers and both request types. Usually when browser starts throwing that error on specific requests, it will continue to do so on the same requests, so maybe the connection is not being closed properly, or something not being freed?

V version

V 0.4.8 aa34047.4d74d72 (but also occurred in 0.4.7)

Environment details (OS name and version, etc.)

Both:

OS: linux, Ubuntu 23.10 Processor: 16 cpus, 64bit, little endian, AMD Ryzen 7 3800X 8-Core Processor

OS: macos, macOS, 14.2.1, 23C71 Processor: 8 cpus, 64bit, little endian, Apple M2

[!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.

Huly®: V_0.6-20923

timurgordon avatar Oct 09 '24 13:10 timurgordon

This bug can't be reliably reproduced unfortunately, which makes it hard to fix.

Do you always get this error, or also from time to time?

medvednikov avatar Oct 12 '24 06:10 medvednikov

we get it a lot, is on the ubuntu server

despiegk avatar Oct 12 '24 06:10 despiegk

@despiegk what Ubuntu version?

medvednikov avatar Oct 12 '24 06:10 medvednikov

OS: linux, Ubuntu 23.10 Processor: 16 cpus, 64bit, little endian, AMD Ryzen 7 3800X 8-Core Processor

its run with

#!/usr/bin/env -S v -n -w -enable-globals run

despiegk avatar Oct 12 '24 06:10 despiegk

It just happens on ubuntu 23.10? I've tried on ubuntu 24.04.1 [wsl], I can't reproduce it. Have you some output with relevant info?

felipensp avatar Oct 12 '24 22:10 felipensp

ok we will try on ubuntu 24.04 as well to see how to reproduce it best on our 23.10 server we have it constantly, easy to reproduce

despiegk avatar Oct 15 '24 03:10 despiegk

vweb有时断开连接,挂起,现已经切换到robyn框架,error 什么时候修复,在切换回来veb 框架 翻译成英文 Vweb sometimes gets disconnected and hangs. Now it has been switched to the Robyn framework. When will the errors be fixed so that we can switch back to the veb framework?

xiaojin20 avatar Nov 24 '24 11:11 xiaojin20

I can confirm this issue happening intermittently (looks like about 25-50% of file upload requests) when running veb in a Docker container - both on Alpine (musl) and Debian (glibc) images with kernel 6.6.3.

NGINX reports [error] 40#40: *460 upstream prematurely closed connection while reading response header from upstream, client: 172.18.0.1, server: , request: "POST /gs/combinepdf HTTP/1.1", ...

syrmel avatar Dec 08 '24 22:12 syrmel

Just confirmed this issue also on kernel 6.12.8.

NGINX: [error] 39#39: *98 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 172.18.0.1, server: , request: "POST /gs/combinepdf HTTP/1.1", ... [error] 39#39: *109 upstream prematurely closed connection while reading response header from upstream, client: 172.18.0.1, server: , request: "POST /gs/combinepdf HTTP/1.1", ...

It works fine on the practically identical vweb version.

syrmel avatar Jan 08 '25 21:01 syrmel

Great fix; I could finally convert my remaining vweb to veb. Thanks!

syrmel avatar Mar 22 '25 09:03 syrmel