You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When sending simultaneous requests to a multithreaded vweb server with a database connection a runtime error occurs.
Expected Behavior
No runtime error
Current Behavior
[Vweb] Running app on http://localhost:8080/
[Vweb] We have 23 workers
message type 0x31 arrived from server while idle
message type 0x32 arrived from server while idle
message type 0x54 arrived from server while idle
message type 0x44 arrived from server while idle
message type 0x43 arrived from server while idle
message type 0x5a arrived from server while idle
7f917c1095c0 : at ???: RUNTIME ERROR: invalid memory access
7f917c1095c0 : at ???: RUNTIME ERROR: invalid memory access
7f917c1095c0 : at ???: RUNTIME ERROR: invalid memory access
7f917c1095c0 : at ???: RUNTIME ERROR: invalid memory access
7f917c1095c0 : at ???: RUNTIME ERROR: invalid memory access
7f917c1095c0 : at ???: RUNTIME ERROR: invalid memory access
Reproduction Steps
Create vweb app:
modulemainimportvwebimportdb.pgstructApp {
vweb.Context
pubmut:
db pg.DB
}
[table: 'users']
structUser {
id int [primary; sql: serial]
name string [nonull]
}
fnmain() {
mutdb:= pg.connect(user: 'dev', password: 'password', dbname: 'db_name')!
sql db {
create table User
}!
sql db {
delete from User where name=='casper64'
}!test_user:= User{name: 'casper64'}
sql db {
insert test_user into User
}!
vweb.run_at(&App{
db: db,
}, port: 8080)!
}
pub fn (mut app App) index() vweb.Result {
rows:= sql app.db {
select from User where name=='casper64'
} or { []User{} }
if rows.len==0 {
return app.not_found()
}
user:= rows[0]
return app.text(user.name)
}
Send multiple requests with wrk
wrk -t 4 -c 20 -d10s http://localhost:8080/
Possible Solution
Currently 1 database connection is shared between all threads. To fix this issue a database pool can be implemented where each worker has it's own connection.
Acknowledgments
I might be able to fix this.
Additional Information/Context
The bug doesn't occur when using a file db like an sqlite file.
mutdb:= sqlite.connect('db.sqlite3') or { panic(err) }
V full version: V 0.3.3 4e498b4.adcd16b
OS: linux, Kali GNU/Linux Rolling (WSL 2)
Processor: 24 cpus, 64bit, little endian, 12th Gen Intel(R) Core(TM) i9-12900K
Describe the bug
When sending simultaneous requests to a multithreaded vweb server with a database connection a runtime error occurs.
Expected Behavior
No runtime error
Current Behavior
Reproduction Steps
Create vweb app:
Send multiple requests with
wrk
Possible Solution
Currently 1 database connection is shared between all threads. To fix this issue a database pool can be implemented where each worker has it's own connection.
Acknowledgments
I might be able to fix this.
Additional Information/Context
The bug doesn't occur when using a file db like an sqlite file.
V version
V 0.3.3 4e498b4.adcd16b
Environment details (OS name and version, etc.)
V full version: V 0.3.3 4e498b4.adcd16b
OS: linux, Kali GNU/Linux Rolling (WSL 2)
Processor: 24 cpus, 64bit, little endian, 12th Gen Intel(R) Core(TM) i9-12900K
getwd: /home/casper
vexe: /opt/v/v
vexe mtime: 2023-04-20 15:59:20
vroot: OK, value: /opt/v
VMODULES: OK, value: /home/casper/.vmodules
VTMP: OK, value: /tmp/v_1000
Git version: git version 2.39.2
Git vroot status: weekly.2023.15-38-gadcd16b1
.git/config present: true
CC version: cc (Debian 12.2.0-14) 12.2.0
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3
The text was updated successfully, but these errors were encountered: