Skip to content

Instantly share code, notes, and snippets.

@jfager
Last active December 18, 2015 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfager/5788001 to your computer and use it in GitHub Desktop.
Save jfager/5788001 to your computer and use it in GitHub Desktop.
Run segfaulting_server with 'rustc segfaulting_server.rs && export RUST_LOG=extra::net_tcp=debug && ./segfaulting_server', then run the client. The server will segfault after the 3rd client request. If you comment out lines 43 & 44, everything works great.
extern mod extra;
use std::{int,io,result,task};
use extra::{net,net_tcp,uv};
fn server(outer_ch: Chan<Chan<~str>>) {
let (accept_port, accept_chan) = stream();
let (finish_port, finish_chan) = stream();
let addr = extra::net_ip::v4::parse_addr("127.0.0.1");
let port = 8080;
do spawn {
let backlog = 128;
let iotask = &uv::global_loop::get();
do net::tcp::listen(addr, port, backlog, iotask, |_| {}) |conn, kill_ch| {
let (res_po, res_ch) = stream::<Option<net_tcp::TcpErrData>>();
accept_chan.send((conn, res_ch));
match res_po.recv() {
Some(err_data) => kill_ch.send(Some(err_data)),
None => ()
}
};
finish_chan.send(());
}
do spawn {
loop {
let (conn, res_ch) = accept_port.recv();
do spawn {
let accept_result = net::tcp::accept(conn);
match accept_result {
Err(accept_error) => {
res_ch.send(Some(accept_error));
},
Ok(sock) => {
res_ch.send(None);
let buf = net::tcp::socket_buf(sock);
let line = buf.read_line();
io::println(fmt!("From client: %s", line));
buf.write_str("pong\n");
//Comment these next 2 lines out and everything's great.
let (inner_po, inner_ch) = stream();
outer_ch.send(inner_ch);
}
}
}
}
}
finish_port.recv();
}
fn main() {
let (outer_po, outer_ch) = stream::<Chan<~str>>();
do task::spawn_with(outer_ch) |ch| { server(ch); }
}
extern mod extra;
use std::{int,io,result};
use extra::{net,net_tcp,uv};
fn main() {
let addr = extra::net_ip::v4::parse_addr("127.0.0.1");
let port = 8080;
let mut counter = 0;
loop {
let iotask = &uv::global_loop::get();
let connect_result = net_tcp::connect(copy addr, port, iotask);
assert!(connect_result.is_ok());
let sock = result::unwrap(connect_result);
let buf = net_tcp::socket_buf(sock);
buf.write_str(fmt!("ping %i\n", counter));
let line = buf.read_line();
io::println(fmt!("From server: %s", line));
counter += 1;
unsafe { std::libc::sleep(1); }
}
}
$ rustc server.rs && export RUST_LOG=extra::net_tcp=debug && ./server
server.rs:3:10: 3:13 warning: unused import [-W unused-imports (default)]
server.rs:3 use std::{int,io,result,task};
^~~
server.rs:3:17: 3:23 warning: unused import [-W unused-imports (default)]
server.rs:3 use std::{int,io,result,task};
^~~~~~
server.rs:46:29: 46:37 warning: unused variable: `inner_po` [-W unused-variable (default)]
server.rs:46 let (inner_po, inner_ch) = stream();
^~~~~~~~
server.rs:59:9: 59:17 warning: unused variable: `outer_po` [-W unused-variable (default)]
server.rs:59 let (outer_po, outer_ch) = stream::<Chan<~str>>();
^~~~~~~~
warning: no debug symbols in executable (-arch x86_64)
rust: ~"addr: &{sin_family: 512, sin_port: 5632, sin_addr: 16777343, sin_zero: (0, 0, 0, 0, 0, 0, 0, 0)}"
rust: ~"\"in interact cb for tcp::accept\""
rust: ~"\"uv_tcp_init successful for client stream\""
rust: ~"successfully accepted client connection: stream 7f96d0d031f0, socket data 7f96d0d032f0"
rust: ~"ptrs: 7f96d0d032f0 7f96d0d032f0"
rust: ~"\"starting tcp::read\""
rust: ~"\"in tcp::read_start before interact loop\""
rust: ~"in tcp::read_start interact cb 140285725122848"
rust: ~"\"success doing uv_read_start\""
rust: ~"\"tcp::read before recv_timeout\""
rust: ~"\"tcp read on_alloc_cb!\""
rust: ~"tcp read on_alloc_cb h: 140285725127152 char_ptr: 140285728421376 sugsize: 65536"
rust: ~"entering on_tcp_read_cb stream: 7f96d0d031f0 nread: 7"
rust: ~"socket data is 7f96d0d032f0"
rust: ~"tcp on_read_cb nread: 7"
rust: ~"\"exiting on_tcp_read_cb\""
rust: ~"\"tcp::read after recv_timeout\""
rust: ~"\"tcp::read got data\""
rust: ~"\"in interact cb for tcp::read_stop\""
rust: ~"\"successfully called uv_read_stop\""
From client: ping 0
rust: ~"in interact cb for tcp::write 140285725122848"
rust: ~"\"uv_write() invoked successfully\""
rust: ~"\"successful write complete\""
rust: ~"interact dtor for tcp_socket stream 140285725127152 loop 140285725122848"
rust: ~"\"tcp_socket_dtor_close_cb exiting..\""
rust: ~"\"exiting dtor for tcp_socket\""
rust: ~"\"in interact cb for tcp::accept\""
rust: ~"\"uv_tcp_init successful for client stream\""
rust: ~"successfully accepted client connection: stream 7f96d0e00db0, socket data 7f96d0e00eb0"
rust: ~"ptrs: 7f96d0e00eb0 7f96d0e00eb0"
rust: ~"\"starting tcp::read\""
rust: ~"\"in tcp::read_start before interact loop\""
rust: ~"in tcp::read_start interact cb 140285725122848"
rust: ~"\"success doing uv_read_start\""
rust: ~"\"tcp read on_alloc_cb!\""
rust: ~"\"tcp::read before recv_timeout\""
rust: ~"tcp read on_alloc_cb h: 140285726166448 char_ptr: 140285736871424 sugsize: 65536"
rust: ~"entering on_tcp_read_cb stream: 7f96d0e00db0 nread: 7"
rust: ~"socket data is 7f96d0e00eb0"
rust: ~"tcp on_read_cb nread: 7"
rust: ~"\"exiting on_tcp_read_cb\""
rust: ~"\"tcp::read after recv_timeout\""
rust: ~"\"tcp::read got data\""
rust: ~"\"in interact cb for tcp::read_stop\""
rust: ~"\"successfully called uv_read_stop\""
From client: ping 1
rust: ~"in interact cb for tcp::write 140285725122848"
rust: ~"\"uv_write() invoked successfully\""
rust: ~"\"successful write complete\""
rust: task failed at 'option::unwrap none', /Users/jason/src/rust/src/libstd/option.rs:268
rust: ~"interact dtor for tcp_socket stream 140285726166448 loop 140285725122848"
rust: ~"\"tcp_socket_dtor_close_cb exiting..\""
rust: ~"\"exiting dtor for tcp_socket\""
rust: domain main @0x7f96d1812410 root task failed
rust: task failed at 'killed', /Users/jason/src/rust/src/libstd/pipes.rs:286
rust: task failed at 'killed', /Users/jason/src/rust/src/libstd/pipes.rs:286
rust: task failed at 'killed', /Users/jason/src/rust/src/libstd/pipes.rs:286
rust: task failed at 'killed', /Users/jason/src/rust/src/libstd/pipes.rs:286
rust: task failed at 'killed', /Users/jason/src/rust/src/libstd/pipes.rs:286
Segmentation fault: 11
@jfager
Copy link
Author

jfager commented Jun 15, 2013

backtrace from gdb:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000
[Switching to process 4515 thread 0x1703]
0x0000000000000000 in ?? ()
(gdb) bt
#0 0x0000000000000000 in ?? ()
#1 0x000000010098bcf2 in uv__io_poll () at rust_task.cpp:1327
#2 0x000000010097dac8 in uv_run () at rust_task.cpp:1327
#3 0x00000001005a0ba1 in rust_uv_run__c_stack_shim ()
#4 0x000000010097cd51 in __morestack () at rust_task.cpp:1327
#5 0x000000010096d5de in rust_task::call_on_c_stack (this=0x100c02120, args=0x1, fn_ptr=0x1) at rust_task.h:484
#6 0x000000010096de0f in upcall_call_shim_on_c_stack (args=0x1051000c8, fn_ptr=0x1050fee30) at rust_upcall.cpp:70
#7 0x000000010064d7ee in uv_iotask::spawn_iotask::anon::expr_fn_21659 ()
#8 0x0000000100660722 in uv_global_loop::spawn_loop::anon::anon::anon::expr_fn_23194 ()
#9 0x00000001001c2590 in unstable::weak_task::weaken_task::_633e817ba3eab3b9::_07pre ()
#10 0x0000000100215c2b in __morestack ()

Previous frame inner to this frame (gdb could not unwind past this frame)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment