-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
-autofree with net.len() Unknown address family ~/v/vlib/net/address.c.v:111 #20635
Comments
https://github.com/vlang/v/blob/master/vlib/picoev/socket_util.c.v#L126-L129
|
Added two more test-data to explain the issue:
import net
for addr in [
':8080' // this works
'127.0.0.1:12700' // this does not
'vlang.io:80',
'google.com:80',
'steampowered.com:80',
'api.steampowered.com:80',
] {
println('${addr}')
for @type in [net.SocketType.tcp, .udp] {
family := net.AddrFamily.unspec
addrs := net.resolve_addrs(addr, family, @type) or {
println('> None')
continue
}
for a in addrs {
f := a.family()
println('> ${a} ${f} ${@type}')
}
}
} |
v -autofree run examples/net_resolve.v ─╯
:8080
> :8080 ip tcp
> :8080 ip udp
127.0.0.1:12700
> unknown enum value tcp
> unknown enum value udp
vlang.io:80
> unknown enum value tcp
> :80 ip tcp
> []:80 ip6 tcp
> []:80 ip6 tcp
> unknown enum value udp
> :80 ip udp
> []:80 ip6 udp
> []:80 ip6 udp
google.com:80
> unknown enum value tcp
> []:80 ip6 tcp
> unknown enum value udp
> []:80 ip6 udp
steampowered.com:80
> unknown enum value tcp
> unknown enum value udp
api.steampowered.com:80
> unknown enum value tcp
> unknown enum value udp Without autofree: :8080
> 0.0.0.0:8080 ip tcp
> 0.0.0.0:8080 ip udp
127.0.0.1:12700
> 127.0.0.1:12700 ip tcp
> 127.0.0.1:12700 ip udp
vlang.io:80
> 104.21.22.45:80 ip tcp
> 172.67.202.167:80 ip tcp
> [2606:4700:3033::6815:162d]:80 ip6 tcp
> [2606:4700:3037::ac43:caa7]:80 ip6 tcp
> 104.21.22.45:80 ip udp
> 172.67.202.167:80 ip udp
> [2606:4700:3033::6815:162d]:80 ip6 udp
> [2606:4700:3037::ac43:caa7]:80 ip6 udp
google.com:80
> 142.250.193.142:80 ip tcp
> [2404:6800:4007:820::200e]:80 ip6 tcp
> 142.250.193.142:80 ip udp
> [2404:6800:4007:820::200e]:80 ip6 udp
steampowered.com:80
> 23.220.236.78:80 ip tcp
> 23.220.236.78:80 ip udp
api.steampowered.com:80
> 23.58.39.59:80 ip tcp
> 23.58.39.59:80 ip udp |
if the host is set to ":" it works, for example: picoev.new(host: ":", port: 8008, cb: perf_route) this is because of these lines in vlib/net/address.c.v:resolve_ipaddrs:170-180 if addr[0] == `:` {
match family {
.ip6 {
return [new_ip6(port, net.addr_ip6_any)]
}
.ip, .unspec {
return [new_ip(port, net.addr_ip_any)]
}
else {}
}
} |
The issue comes down to something wrong when pushing an item to an array when using -autofree
|
same with |
After simplifying: fn foo () ![]int {
mut arr := []int{}
arr << 1
return arr
}
fn main() {
a := foo()!
println(a)
} v -autofree -cg run a.v:
|
fn foo () ![]int {
mut arr := []int{}
arr << 1
return arr
}
fn main() {
a := foo()!
println(a)
} TCCv -autofree -cg run <file> [10843]
free(): double free detected in tcache 2
0x7336a4a9eb1c: at ???: RUNTIME ERROR: abort() called
0x7336a4a4526e: by ???
0x7336a4a288ff: by ???
0x7336a4a297b6: by ???
0x7336a4aa8fe5: by ???
0x7336a4aab54f: by ???
0x7336a4aadd9e: by ???
/tmp/v_1000/parse.01JBQQGPM5EFE4Z0GPSS78DPR0.tmp.c:7616: by _v_free
/tmp/v_1000/parse.01JBQQGPM5EFE4Z0GPSS78DPR0.tmp.c:6760: by array_free
/tmp/v_1000/parse.01JBQQGPM5EFE4Z0GPSS78DPR0.tmp.c:13518: by main__main
/tmp/v_1000/parse.01JBQQGPM5EFE4Z0GPSS78DPR0.tmp.c:13565: by main |
Describe the bug
v -autofree -cg run autofree.v
================ V panic ================ module: net function: len() message: Unknown address family file: /Users/.../v/vlib/net/address.c.v:111 v hash: bb9eaca ========================================= 0 autofree 0x00000001000872b8 net__Addr_len + 360 1 autofree 0x0000000100092e40 picoev__listen + 1336 2 autofree 0x000000010009267c picoev__new + 84 3 autofree 0x0000000100093f3c main__main + 152 4 autofree 0x0000000100095a54 main + 72 5 dyld 0x00000001a70f7e50 start + 2544
Reproduction Steps
Run this code with:
v -autofree -cg run autofree.v
Expected Behavior
Server should start similar to running without the -autofree flag
Current Behavior
Crashes:
================ V panic ================ module: net function: len() message: Unknown address family file: /Users/.../v/vlib/net/address.c.v:111 v hash: bb9eaca ========================================= 0 autofree 0x00000001000872b8 net__Addr_len + 360 1 autofree 0x0000000100092e40 picoev__listen + 1336 2 autofree 0x000000010009267c picoev__new + 84 3 autofree 0x0000000100093f3c main__main + 152 4 autofree 0x0000000100095a54 main + 72 5 dyld 0x00000001a70f7e50 start + 2544
Possible Solution
Tempfix: picoev fixed with detecting -autofree
Permfix: check and fix how autofree does for net.c.v
Additional Information/Context
No response
V version
0.4.4
Environment details (OS name and version, etc.)
Mac (same error on linux too)
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.
The text was updated successfully, but these errors were encountered: