rust icon indicating copy to clipboard operation
rust copied to clipboard

Crash "free(): invalid pointer" in sock.read() in a separate task

Open ttaubert opened this issue 14 years ago • 11 comments

I compiled a little tcp listener example that spawns tasks per connection. The sock.read() call fails when it receives data - just use telnet to connect, type something and hit enter:

extern mod std;

use std::uv;
use std::net::{ip, tcp};

fn main() {
  let iotask = uv::global_loop::get();
  let addr = ip::v4::parse_addr("127.0.0.1");

  tcp::listen(addr, 4000u, 128u, iotask,
    |kill_ch| {
      #info("server is listening");
    },

    |new_conn, kill_ch| {
      let port = comm::Port::<()>();
      let chan = port.chan();

      do task::spawn_sched(task::ManualThreads(1u)) {
        let accept_result = tcp::accept(new_conn);
        chan.send(());

        if accept_result.is_err() {
          let err_data = result::unwrap_err(accept_result);
          kill_ch.send(Some(err_data));
        } else {
          let sock = result::unwrap(accept_result);
          let read_result = sock.read(0);
          if read_result.is_ok() {
            io::println("success");
          } else {
            kill_ch.send(None);
          }
        }
      }

      chan.recv();
    }
  );
}

This used to work with Rust 0.3 but crashes now with the following message:

*** glibc detected *** ./test: free(): invalid pointer: 0x00007f94c41027a8 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7ec96)[0x7f94cd920c96]
/home/tim/workspace/rust-memcached/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/librustrt.so(+0x36e6d)[0x7f94cdeade6d]
/home/tim/workspace/rust-memcached/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/librustrt.so(upcall_call_shim_on_c_stack+0x87)[0x7f94cde97cd7]
/home/tim/workspace/rust-memcached/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/libstd-4782a756585a81-0.4.so(+0x63210)[0x7f94cdf44210]
/home/tim/workspace/rust-memcached/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/librustrt.so(+0x36e6d)[0x7f94cdeade6d]
/home/tim/workspace/rust-memcached/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/librustrt.so(upcall_call_shim_on_rust_stack+0xcf)[0x7f94cde97fff]
/home/tim/workspace/rust-memcached/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/libstd-4782a756585a81-0.4.so(+0x60a95)[0x7f94cdf41a95]
/home/tim/workspace/rust-memcached/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/librustrt.so(+0x3af77)[0x7f94cdeb1f77]
/home/tim/workspace/rust-memcached/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/librustrt.so(+0x4099f)[0x7f94cdeb799f]
/home/tim/workspace/rust-memcached/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/librustrt.so(+0x458b8)[0x7f94cdebc8b8]
/home/tim/workspace/rust-memcached/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/librustrt.so(+0x37d12)[0x7f94cdeaed12]
/home/tim/workspace/rust-memcached/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/librustrt.so(+0x36e6d)[0x7f94cdeade6d]
/home/tim/workspace/rust-memcached/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/librustrt.so(upcall_call_shim_on_c_stack+0x87)[0x7f94cde97cd7]
/home/tim/workspace/rust-memcached/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/libstd-4782a756585a81-0.4.so(+0x78b6e)[0x7f94cdf59b6e]
/home/tim/workspace/rust-memcached/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/libstd-4782a756585a81-0.4.so(+0x7ea0e)[0x7f94cdf5fa0e]
/home/tim/workspace/rust-memcached/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/libstd-4782a756585a81-0.4.so(+0xe8710)[0x7f94cdfc9710]
/home/tim/workspace/rust-memcached/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/libcore-c3ca5d77d81b46c1-0.4.so(_ZN7private11weaken_task17_a2f0b02d17df416d3_04E+0xd2)[0x7f94ce150fe2]
/home/tim/workspace/rust-memcached/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/libstd-4782a756585a81-0.4.so(+0x7e4b9)[0x7f94cdf5f4b9]
/home/tim/workspace/rust-memcached/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/libcore-c3ca5d77d81b46c1-0.4.so(+0x76322)[0x7f94ce136322]
/home/tim/workspace/rust-memcached/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/libcore-c3ca5d77d81b46c1-0.4.so(+0xb6000)[0x7f94ce176000]
/home/tim/workspace/rust-memcached/../../../../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib/librustrt.so(_Z18task_start_wrapperP10spawn_args+0x24)[0x7f94cde960e4]

ttaubert avatar Oct 06 '12 11:10 ttaubert

Any update here? This is blocking even the simplest server app.

ttaubert avatar Oct 10 '12 19:10 ttaubert

Is this on a 32-bit system by chance? uv is completely broken there due to FFI bugs.

brson avatar Oct 10 '12 21:10 brson

Oh, it's obviously a 64-bit system based on the logs. Hm.

brson avatar Oct 10 '12 21:10 brson

@ttaubert: It's working on OSX lion for me, and I have heard that it's working on an ubuntu 12.04 x86_64 box. What platform are you running into this on, and is it still occurring on the latest incoming branch?

erickt avatar Oct 10 '12 21:10 erickt

Thanks for the quick response, I'm on Ubuntu 12.04 as well. Will try the latest incoming branch and report back.

ttaubert avatar Oct 10 '12 21:10 ttaubert

The provided test file still crashes for me with the latest incoming.

ttaubert avatar Oct 10 '12 21:10 ttaubert

@ttaubert any chance you can hop in our irc channel #rust on irc.mozilla.org? You can use this link if you don't already have a client set up.

erickt avatar Oct 10 '12 21:10 erickt

So in the middle of trying to reproduce this it suddenly stopped occuring. I have no idea why. Closing for now.

ttaubert avatar Oct 11 '12 07:10 ttaubert

There's been another report of this error.

brson avatar Oct 23 '12 20:10 brson

Won't be fixed in 0.6

brson avatar Mar 31 '13 04:03 brson

Closing this one as WONTFIX, the underlying APIs here are going to be removed when we shift to the new scheduler (shortly), and we have no reports (yet) of such issues in the new scheduler. Sorry, limited time :(

graydon avatar May 29 '13 19:05 graydon