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.75k stars 2.16k forks source link

Removing code while executing in hot code mode may cause Segmentation fault #6669

Open Anthony-Gaudino opened 3 years ago

Anthony-Gaudino commented 3 years ago

V version: 0.1.29 c3626bf.8ffbcdc OS: linux, Ubuntu 20.04.1 LTS

What did you do? While running a hot code, if one deletes the [live] it causes a Segmentation fault.

module main

import time
import os

[live] // <- Delete this while running
fn print_message() {
    println('Hello! Modify this message while the program is running.')
}

fn main() {
    for {
        print_message()
        time.sleep_ms(500)
    }
}

Also deleting all lines under the [live] also causes a Segmentation fault.

What did you expect to see? Execute the program again without hot code reloading and finish execution or display a compilation error.

What did you see instead?

Hello! Modify this message while the program is running.
>       compilation cmd: /home/anthony/Documents/v2/v   -sharedlive -shared -o /home/anthony/.cache/tmp.2.bug ./bug.v
Hello! Modify this message while the program is running.
Hello! Modify this message while the program is running.
compilation took: 777ms
> compile_and_reload_shared_lib compiled: /home/anthony/.cache/tmp.2.bug.so
live mutex locking...
live mutex locked
> load_lib OK, new live_lib: 0x7f1ba80015a0
live mutex unlocking...
live mutex unlocked
Segmentation fault (core dumped)
ArtemkaKun commented 2 years ago

Still valid, an actual error message (on the V 0.2.4)

signal 11: segmentation fault
/tmp/v_1000/main.2911200685921105863.tmp.c:7513: at print_backtrace: Backtrace
/tmp/v_1000/main.2911200685921105863.tmp.c:7579: by v_segmentation_fault_handler