Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When a port is unavailable, veb segfaults #22292

Closed
prashanth-hegde opened this issue Sep 24, 2024 · 0 comments · Fixed by #22463
Closed

When a port is unavailable, veb segfaults #22292

prashanth-hegde opened this issue Sep 24, 2024 · 0 comments · Fixed by #22463
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: veb Bugs/feature requests, that are related to the `veb`, V's official web framework.

Comments

@prashanth-hegde
Copy link
Contributor

prashanth-hegde commented Sep 24, 2024

V doctor:

V full version: V 0.4.7 0117c7f.03e0b9e
OS: macos, macOS, 14.6.1, 23G93
Processor: 10 cpus, 64bit, little endian, Apple M1 Max

getwd: /Users/Z002DCM
vexe: /Users/Z002DCM/apps/v/v
vexe mtime: 2024-09-24 03:42:14

vroot: OK, value: /Users/Z002DCM/apps/v
VMODULES: OK, value: /Users/Z002DCM/.vmodules
VTMP: OK, value: /tmp/v_503

Git version: git version 2.39.5 (Apple Git-154)
Git vroot status: weekly.2024.39-3-g03e0b9e6
.git/config present: true

CC version: Apple clang version 16.0.0 (clang-1600.0.26.3)
thirdparty/tcc status: thirdparty-macos-arm64 713692d4

What did you do?
Run the same veb instance twice on the same machine.
The first run works fine, and the port 8080 will be serving.
The second run fails to acquire the port 8080. Instead of failing gracefully, it throws a segfaiult

./v -g -o vdbg cmd/v && ./vdbg /tmp/x.v

import veb

pub struct User {
pub mut:
    name string
    id   int
}

// Our context struct must embed `veb.Context`!
pub struct Context {
    veb.Context
pub mut:
    // In the context struct we store data that could be different
    // for each request. Like a User struct or a session id
    user       User
    session_id string
}

pub struct App {
pub:
    // In the app struct we store data that should be accessible by all endpoints.
    // For example, a database or configuration values.
    secret_key string
}

// This is how endpoints are defined in veb. This is the index route
pub fn (app &App) index(mut ctx Context) veb.Result {
    return ctx.text('Hello V! The secret key is "${app.secret_key}"')
}

fn main() {
    mut app := &App{
        secret_key: 'secret'
    }
    // Pass the App and context type and start the web server on port 8080
    veb.run[App, Context](mut app, 8080)
}

What did you expect to see?

When a port is unavailable, veb should fail gracefully

What did you see instead?

[veb] Running app on http://localhost:8080/
Error during listen: net: socket error: 48; binding to :8080 failed
signal 11: segmentation fault
0   libsystem_platform.dylib            0x000000018ba72584 _sigtramp + 56
1   x                                   0x000000010493b64c picoev__Picoev_loop_once + 24
2   x                                   0x000000010493d5f8 picoev__Picoev_serve + 204
3   x                                   0x000000010495cfe8 veb__run_at_T_main__App_main__Context + 1924
4   x                                   0x000000010495c808 veb__run_T_main__App_main__Context + 116
5   x                                   0x0000000104961ee8 main__main + 68
6   x                                   0x0000000104963a6c main + 88
7   dyld                                0x000000018b6b7154 start + 2476

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 esquerbatua added Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: veb Bugs/feature requests, that are related to the `veb`, V's official web framework. Bug This tag is applied to issues which reports bugs. labels Sep 26, 2024
@esquerbatua esquerbatua self-assigned this Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: veb Bugs/feature requests, that are related to the `veb`, V's official web framework.
Projects
None yet
2 participants