vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.87k stars 2.17k forks source link

veb, server drops connection, error parsing request #22464

Open timurgordon opened 1 month ago

timurgordon commented 1 month ago

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

medvednikov commented 1 month ago

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?

despiegk commented 1 month ago

we get it a lot, is on the ubuntu server

medvednikov commented 1 month ago

@despiegk what Ubuntu version?

despiegk commented 1 month ago

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

felipensp commented 1 month ago

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?

despiegk commented 1 month ago

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

xiaojin20 commented 5 days ago

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?