Prevent ending tokio task before ending an std thread

#1

Hello,
I’m trying to create a software testing suite by using rust that will able to capture, manipulate and fuzz protocols and APIs.
One part of this suite is a TCP proxy that must able to forge SSL certificates, intercept, manipulate and repeating packets by using Lua lang. for implementing this, I’m using tokio tcpstream for sending and receiving packets and another std thread that’s handle Lua that its lifetime is inside of a tcpstream.
My problem: Since the Lua thread’s lifetime is inside of a tokio task, sometimes tokio task (tcpstream) will end earlier that Lua thread.
for example, if I change buffer size in Lua script to 1 byte and try to connect to my ssh server, it is possible the following error will occur (by reducing buffer size error possibility will be reduced).

thread 'lua_thread' panicked at 'no Task is currently running', /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/task_impl/mod.rs:44:9
stack backtrace:
   0:        0x108e85113 - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h9a87463918f2aff9
                               at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1:        0x108e80fdc - std::sys_common::backtrace::_print::h54740e69908f9100
                               at src/libstd/sys_common/backtrace.rs:70
   2:        0x108e83d51 - std::panicking::default_hook::{{closure}}::h519f1fd4b67636f1
                               at src/libstd/sys_common/backtrace.rs:58
                               at src/libstd/panicking.rs:200
   3:        0x108e83a57 - std::panicking::default_hook::h5442e3ae9abda811
                               at src/libstd/panicking.rs:215
   4:        0x108e844de - <std::panicking::begin_panic::PanicPayload<A> as core::panic::BoxMeUp>::get::hfb37cabc364058a5
                               at src/libstd/panicking.rs:478
   5:        0x108e6c607 - std::sys::unix::condvar::Condvar::wait::hb4c8c761bc508345
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panicking.rs:412
   6:        0x108e69d5e - core::sync::atomic::fence::h5428020e71ffb116
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/task_impl/mod.rs:44
   7:        0x108e69dc3 - core::sync::atomic::fence::h5428020e71ffb116
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/task_impl/mod.rs:115
   8:        0x108ca4d1e - <futures::sync::bilock::BiLock<T>>::poll_lock::he2c5f2636f790129
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/sync/bilock.rs:96
   9:        0x108ca5e69 - <tokio_io::split::WriteHalf<T> as std::io::Write>::write::hea8f0cdde92944ed
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-io-0.1.12/src/split.rs:80
  10:        0x108ca56ec - std::io::Write::write_all::h1763a0b8ecd8ef7b
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/io/mod.rs:1059
  11:        0x108c92b13 - socket::lua::Lua::set_write_func::{{closure}}::{{closure}}::hda82a4f78ca0f39c
                               at src/lua.rs:102
  12:        0x108cafbef - rlua::context::Context::create_function::{{closure}}::h6d7b3fbf0ab8a5c3
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/context.rs:178
  13:        0x108ccdfe6 - rlua::context::Context::create_callback::call_callback::{{closure}}::h3f249207bc3cc4f0
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/context.rs:754
  14:        0x108cc569b - rlua::util::callback_error::{{closure}}::h518dd6692b19a43a
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/util.rs:370
  15:        0x108ccf8f3 - rlua::context::ref_stack_pop::hb4eb7f070939ab2c
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panic.rs:309
  16:        0x108ce7140 - core::ptr::swap_nonoverlapping_bytes::heb52961decd8e6ad
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panicking.rs:297
  17:        0x108e86d0e - panic_unwind::dwarf::eh::read_encoded_pointer::h52da212b8b68c3fd
                               at src/libpanic_unwind/lib.rs:92
  18:        0x108ce6ca2 - core::ptr::swap_nonoverlapping_bytes::heb52961decd8e6ad
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panicking.rs:276
  19:        0x108cd0463 - std::sys_common::poison::Flag::borrow::h178b2235a8374f6e
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panic.rs:388
  20:        0x108cc38fb - rlua::util::userdata_destructor::{{closure}}::hd921c42f0e26fd08
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/util.rs:370
  21:        0x108ccdac0 - rlua::context::Context::create_callback::call_callback::h23b720da50be1411
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/context.rs:735
  22:        0x108cf9dd2 - moveresults
                               at lua/ldo.c:434
  23:        0x108d1e6ea - copy2buff
                               at lua/lvm.c:1134
  24:        0x108cfa422 - tryfuncTM
                               at lua/ldo.c:499
  25:        0x108cfa4e8 - stackerror
                               at lua/ldo.c:509
  26:        0x108cecf9e - f_call
                               at lua/lapi.c:943
  27:        0x108cf925d - seterrorobj
                               at lua/ldo.c:142
  28:        0x108cfae54 - unroll
                               at lua/ldo.c:729
  29:        0x108cece49 - auxsetstr
                               at lua/lapi.c:969
  30:        0x108ce2019 - rlua::ffi::lua_call::h8bec08fe840b34da
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/ffi.rs:327
  31:        0x108ce290a - rlua::ffi::lua_replace::h54cb2450536a055c
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/function.rs:75
  32:        0x108ccf415 - rlua::context::Context::create_callback::{{closure}}::h6374d8db13ef878f
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/context.rs:930
  33:        0x108ccf12c - rlua::context::Context::create_callback::{{closure}}::h6374d8db13ef878f
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/context.rs:901
  34:        0x108c91e85 - socket::lua::Lua::run::{{closure}}::{{closure}}::hdb423f28edd978bd
                               at src/lua.rs:38
  35:        0x108cbe4ca - rlua::lua::Lua::context::h1222252a7dadd35b
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/lua.rs:183
  36:        0x108c91ef4 - socket::lua::Lua::run::{{closure}}::h15023a4c3aff89e3
                               at src/lua.rs:36
  37:        0x108cb9b9c - std::sys_common::backtrace::__rust_begin_short_backtrace::h3617ced09f5dd21e
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/sys_common/backtrace.rs:135
  38:        0x108cbf26c - std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}}::hb7ce677e43aef6b0
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/thread/mod.rs:469
  39:        0x108ca0f5c - <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::hf017a9fa5eeb3f37
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panic.rs:309
  40:        0x108cbe459 - std::panicking::try::do_call::h7c4def0a0ca5c0cd
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panicking.rs:297
  41:        0x108e86d0e - panic_unwind::dwarf::eh::read_encoded_pointer::h52da212b8b68c3fd
                               at src/libpanic_unwind/lib.rs:92
  42:        0x108cbe39a - std::panicking::try::ha86206ab30a997cf
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panicking.rs:276
  43:        0x108ca0f8c - std::panic::catch_unwind::hdb9ca22f9276f0b0
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panic.rs:388
  44:        0x108cbf0c5 - std::thread::Builder::spawn_unchecked::{{closure}}::h4a2ad2cd4398560b
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/thread/mod.rs:468
  45:        0x108cbf317 - <F as alloc::boxed::FnBox<A>>::call_box::h218690c0e8b4c67c
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/liballoc/boxed.rs:734
  46:        0x108e867ab - std::sys::unix::thread::Thread::new::thread_start::h2ccd51efe09a6d88
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/liballoc/boxed.rs:744
                               at src/libstd/sys_common/thread.rs:14
                               at src/libstd/sys/unix/thread.rs:81
  47:     0x7fff7cbf3304 - _pthread_body
  48:     0x7fff7cbf626e - _pthread_start

My Question : How Is possible to wait tokio task until the std thread will be ended ?

P.S.: I pushed my codes in github.com/SajjadPourali/tcp_agent/ , code need polish and after solving this issue I will fix it.

#2

Why did you comment out the join here?

Know that tokio::spawn in any case will spawn something with a separate lifetime, there is also methods like run and block_on…

1 Like
#3

How do I reproduce the issue? cargo run just runs without any output…

1 Like
#4

@najamelan : thank you for your response.

Because, it blocks TCPStream’s thread, therefore read/write on that socket will be impossible.

I couldn’t use block_on with std::thread could please give me an example ?

Actually it’s a TCP proxy between 127.0.0.1:12345 and 198.143.180.42:22

listen="127.0.0.1:12345"
#connect="127.0.0.1:2222"
connect="198.143.180.42:22"

first of all please change recive(2) to recive(1) (it’s a buffer size by byte). after that you can run the program.
after running with cargo run, please run ssh root@127.0.0.1 -p 12345 in several terminals ( 198.143.180.42 is my server feel free to try).

#5

it ask me for root password on 3 terminals, so I take it’s working. Is it a problem that happens only sometimes?

1 Like
#6

Yes, please wait I will create an asciinema video.

#7

Ok, so if i understand it correctly, tokio::spawn(req_handler); spawns the req_handler future and then closes the tcp connection before that future has finished work. Is that what happens?

1 Like
#8

Almost Yes, before finishing lua’s thread, tcp connection will be closed.
https://asciinema.org/a/HA5s7Fr93MUCu2ydg4hlNrDuC

#9

hmm, but the backtrace, it has no reference to any line in your code?

1 Like
#10

back-trace is exactly same as first post’s back-trace.

Summary
thread 'lua_thread' panicked at 'no Task is currently running', /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/task_impl/mod.rs:44:9
stack backtrace:
   0:        0x108e85113 - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h9a87463918f2aff9
                               at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1:        0x108e80fdc - std::sys_common::backtrace::_print::h54740e69908f9100
                               at src/libstd/sys_common/backtrace.rs:70
   2:        0x108e83d51 - std::panicking::default_hook::{{closure}}::h519f1fd4b67636f1
                               at src/libstd/sys_common/backtrace.rs:58
                               at src/libstd/panicking.rs:200
   3:        0x108e83a57 - std::panicking::default_hook::h5442e3ae9abda811
                               at src/libstd/panicking.rs:215
   4:        0x108e844de - <std::panicking::begin_panic::PanicPayload<A> as core::panic::BoxMeUp>::get::hfb37cabc364058a5
                               at src/libstd/panicking.rs:478
   5:        0x108e6c607 - std::sys::unix::condvar::Condvar::wait::hb4c8c761bc508345
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panicking.rs:412
   6:        0x108e69d5e - core::sync::atomic::fence::h5428020e71ffb116
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/task_impl/mod.rs:44
   7:        0x108e69dc3 - core::sync::atomic::fence::h5428020e71ffb116
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/task_impl/mod.rs:115
   8:        0x108ca4d1e - <futures::sync::bilock::BiLock<T>>::poll_lock::he2c5f2636f790129
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/sync/bilock.rs:96
   9:        0x108ca5e69 - <tokio_io::split::WriteHalf<T> as std::io::Write>::write::hea8f0cdde92944ed
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-io-0.1.12/src/split.rs:80
  10:        0x108ca56ec - std::io::Write::write_all::h1763a0b8ecd8ef7b
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/io/mod.rs:1059
  11:        0x108c92b13 - socket::lua::Lua::set_write_func::{{closure}}::{{closure}}::hda82a4f78ca0f39c
                               at src/lua.rs:102
  12:        0x108cafbef - rlua::context::Context::create_function::{{closure}}::h6d7b3fbf0ab8a5c3
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/context.rs:178
  13:        0x108ccdfe6 - rlua::context::Context::create_callback::call_callback::{{closure}}::h3f249207bc3cc4f0
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/context.rs:754
  14:        0x108cc569b - rlua::util::callback_error::{{closure}}::h518dd6692b19a43a
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/util.rs:370
  15:        0x108ccf8f3 - rlua::context::ref_stack_pop::hb4eb7f070939ab2c
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panic.rs:309
  16:        0x108ce7140 - core::ptr::swap_nonoverlapping_bytes::heb52961decd8e6ad
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panicking.rs:297
  17:        0x108e86d0e - panic_unwind::dwarf::eh::read_encoded_pointer::h52da212b8b68c3fd
                               at src/libpanic_unwind/lib.rs:92
  18:        0x108ce6ca2 - core::ptr::swap_nonoverlapping_bytes::heb52961decd8e6ad
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panicking.rs:276
  19:        0x108cd0463 - std::sys_common::poison::Flag::borrow::h178b2235a8374f6e
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panic.rs:388
  20:        0x108cc38fb - rlua::util::userdata_destructor::{{closure}}::hd921c42f0e26fd08
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/util.rs:370
  21:        0x108ccdac0 - rlua::context::Context::create_callback::call_callback::h23b720da50be1411
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/context.rs:735
  22:        0x108cf9dd2 - moveresults
                               at lua/ldo.c:434
  23:        0x108d1e6ea - copy2buff
                               at lua/lvm.c:1134
  24:        0x108cfa422 - tryfuncTM
                               at lua/ldo.c:499
  25:        0x108cfa4e8 - stackerror
                               at lua/ldo.c:509
  26:        0x108cecf9e - f_call
                               at lua/lapi.c:943
  27:        0x108cf925d - seterrorobj
                               at lua/ldo.c:142
  28:        0x108cfae54 - unroll
                               at lua/ldo.c:729
  29:        0x108cece49 - auxsetstr
                               at lua/lapi.c:969
  30:        0x108ce2019 - rlua::ffi::lua_call::h8bec08fe840b34da
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/ffi.rs:327
  31:        0x108ce290a - rlua::ffi::lua_replace::h54cb2450536a055c
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/function.rs:75
  32:        0x108ccf415 - rlua::context::Context::create_callback::{{closure}}::h6374d8db13ef878f
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/context.rs:930
  33:        0x108ccf12c - rlua::context::Context::create_callback::{{closure}}::h6374d8db13ef878f
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/context.rs:901
  34:        0x108c91e85 - socket::lua::Lua::run::{{closure}}::{{closure}}::hdb423f28edd978bd
                               at src/lua.rs:38
  35:        0x108cbe4ca - rlua::lua::Lua::context::h1222252a7dadd35b
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/lua.rs:183
  36:        0x108c91ef4 - socket::lua::Lua::run::{{closure}}::h15023a4c3aff89e3
                               at src/lua.rs:36
  37:        0x108cb9b9c - std::sys_common::backtrace::__rust_begin_short_backtrace::h3617ced09f5dd21e
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/sys_common/backtrace.rs:135
  38:        0x108cbf26c - std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}}::hb7ce677e43aef6b0
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/thread/mod.rs:469
  39:        0x108ca0f5c - <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::hf017a9fa5eeb3f37
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panic.rs:309
  40:        0x108cbe459 - std::panicking::try::do_call::h7c4def0a0ca5c0cd
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panicking.rs:297
  41:        0x108e86d0e - panic_unwind::dwarf::eh::read_encoded_pointer::h52da212b8b68c3fd
                               at src/libpanic_unwind/lib.rs:92
  42:        0x108cbe39a - std::panicking::try::ha86206ab30a997cf
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panicking.rs:276
  43:        0x108ca0f8c - std::panic::catch_unwind::hdb9ca22f9276f0b0
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panic.rs:388
  44:        0x108cbf0c5 - std::thread::Builder::spawn_unchecked::{{closure}}::h4a2ad2cd4398560b
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/thread/mod.rs:468
  45:        0x108cbf317 - <F as alloc::boxed::FnBox<A>>::call_box::h218690c0e8b4c67c
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/liballoc/boxed.rs:734
  46:        0x108e867ab - std::sys::unix::thread::Thread::new::thread_start::h2ccd51efe09a6d88
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/liballoc/boxed.rs:744
                               at src/libstd/sys_common/thread.rs:14
                               at src/libstd/sys/unix/thread.rs:81
  47:     0x7fff7cbf3304 - _pthread_body
  48:     0x7fff7cbf626e - _pthread_start

  34:        0x108c91e85 - socket::lua::Lua::run::{{closure}}::{{closure}}::hdb423f28edd978bd
                               at src/lua.rs:38
  35:        0x108cbe4ca - rlua::lua::Lua::context::h1222252a7dadd35b
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/lua.rs:183
  36:        0x108c91ef4 - socket::lua::Lua::run::{{closure}}::h15023a4c3aff89e3
                               at src/lua.rs:36

it’s related to lua’s thread.

#11

If you change this spawn for rt.run, does it still happen?

1 Like
#12

I’m using runtime it’s not have a run() method. I think I couldn’t understand your meaning.

#13

I would try with https://docs.rs/tokio/0.1/tokio/runtime/struct.Runtime.html#method.block_on_all then

1 Like
#14
thread 'lua_thread' panicked at 'no Task is currently running', /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/task_impl/mod.rs:44:9
stack backtrace:
   0:        0x106334b33 - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h9a87463918f2aff9
                               at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1:        0x1063309fc - std::sys_common::backtrace::_print::h54740e69908f9100
                               at src/libstd/sys_common/backtrace.rs:70
   2:        0x106333771 - std::panicking::default_hook::{{closure}}::h519f1fd4b67636f1
                               at src/libstd/sys_common/backtrace.rs:58
                               at src/libstd/panicking.rs:200
   3:        0x106333477 - std::panicking::default_hook::h5442e3ae9abda811
                               at src/libstd/panicking.rs:215
   4:        0x106333efe - <std::panicking::begin_panic::PanicPayload<A> as core::panic::BoxMeUp>::get::hfb37cabc364058a5
                               at src/libstd/panicking.rs:478
   5:        0x10631c027 - std::sys::unix::condvar::Condvar::wait::hb4c8c761bc508345
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panicking.rs:412
   6:        0x10631977e - core::sync::atomic::fence::h5428020e71ffb116
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/task_impl/mod.rs:44
   7:        0x1063197e3 - core::sync::atomic::fence::h5428020e71ffb116
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/task_impl/mod.rs:115
   8:        0x10614f9fe - <futures::sync::bilock::BiLock<T>>::poll_lock::he2c5f2636f790129
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/sync/bilock.rs:96
   9:        0x106150cd9 - <tokio_io::split::WriteHalf<T> as std::io::Write>::write::hea8f0cdde92944ed
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-io-0.1.12/src/split.rs:80
  10:        0x10615055c - std::io::Write::write_all::h1763a0b8ecd8ef7b
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/io/mod.rs:1059
  11:        0x10613bb93 - socket::lua::Lua::set_write_func::{{closure}}::{{closure}}::hda82a4f78ca0f39c
                               at src/lua.rs:102
  12:        0x10615b07f - rlua::context::Context::create_function::{{closure}}::h6d7b3fbf0ab8a5c3
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/context.rs:178
  13:        0x10617d746 - rlua::context::Context::create_callback::call_callback::{{closure}}::h3f249207bc3cc4f0
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/context.rs:754
  14:        0x106174dfb - rlua::util::callback_error::{{closure}}::h518dd6692b19a43a
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/util.rs:370
  15:        0x10617f053 - rlua::context::ref_stack_pop::hb4eb7f070939ab2c
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panic.rs:309
  16:        0x1061968a0 - core::ptr::swap_nonoverlapping_bytes::heb52961decd8e6ad
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panicking.rs:297
  17:        0x10633672e - panic_unwind::dwarf::eh::read_encoded_pointer::h52da212b8b68c3fd
                               at src/libpanic_unwind/lib.rs:92
  18:        0x106196402 - core::ptr::swap_nonoverlapping_bytes::heb52961decd8e6ad
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panicking.rs:276
  19:        0x10617fbc3 - std::sys_common::poison::Flag::borrow::h178b2235a8374f6e
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panic.rs:388
  20:        0x10617305b - rlua::util::userdata_destructor::{{closure}}::hd921c42f0e26fd08
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/util.rs:370
  21:        0x10617d220 - rlua::context::Context::create_callback::call_callback::h23b720da50be1411
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/context.rs:735
  22:        0x1061a9532 - moveresults
                               at lua/ldo.c:434
  23:        0x1061cde4a - copy2buff
                               at lua/lvm.c:1134
  24:        0x1061a9b82 - tryfuncTM
                               at lua/ldo.c:499
  25:        0x1061a9c48 - stackerror
                               at lua/ldo.c:509
  26:        0x10619c6fe - f_call
                               at lua/lapi.c:943
  27:        0x1061a89bd - seterrorobj
                               at lua/ldo.c:142
  28:        0x1061aa5b4 - unroll
                               at lua/ldo.c:729
  29:        0x10619c5a9 - auxsetstr
                               at lua/lapi.c:969
  30:        0x106191779 - rlua::ffi::lua_call::h8bec08fe840b34da
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/ffi.rs:327
  31:        0x10619206a - rlua::ffi::lua_replace::h54cb2450536a055c
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/function.rs:75
  32:        0x10617eb75 - rlua::context::Context::create_callback::{{closure}}::h6374d8db13ef878f
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/context.rs:930
  33:        0x10617e88c - rlua::context::Context::create_callback::{{closure}}::h6374d8db13ef878f
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/context.rs:901
  34:        0x10613af05 - socket::lua::Lua::run::{{closure}}::{{closure}}::hdb423f28edd978bd
                               at src/lua.rs:38
  35:        0x10616baba - rlua::lua::Lua::context::h1222252a7dadd35b
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/rlua-0.16.2/src/lua.rs:183
  36:        0x10613af74 - socket::lua::Lua::run::{{closure}}::h15023a4c3aff89e3
                               at src/lua.rs:36
  37:        0x1061668dc - std::sys_common::backtrace::__rust_begin_short_backtrace::h3617ced09f5dd21e
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/sys_common/backtrace.rs:135
  38:        0x10616c85c - std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}}::hb7ce677e43aef6b0
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/thread/mod.rs:469
  39:        0x10614bc3c - <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::hf017a9fa5eeb3f37
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panic.rs:309
  40:        0x10616ba49 - std::panicking::try::do_call::h7c4def0a0ca5c0cd
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panicking.rs:297
  41:        0x10633672e - panic_unwind::dwarf::eh::read_encoded_pointer::h52da212b8b68c3fd
                               at src/libpanic_unwind/lib.rs:92
  42:        0x10616b98a - std::panicking::try::ha86206ab30a997cf
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panicking.rs:276
  43:        0x10614bc6c - std::panic::catch_unwind::hdb9ca22f9276f0b0
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panic.rs:388
  44:        0x10616c6b5 - std::thread::Builder::spawn_unchecked::{{closure}}::h4a2ad2cd4398560b
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/thread/mod.rs:468
  45:        0x10616c907 - <F as alloc::boxed::FnBox<A>>::call_box::h218690c0e8b4c67c
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/liballoc/boxed.rs:734
  46:        0x1063361cb - std::sys::unix::thread::Thread::new::thread_start::h2ccd51efe09a6d88
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/liballoc/boxed.rs:744
                               at src/libstd/sys_common/thread.rs:14
                               at src/libstd/sys/unix/thread.rs:81
  47:     0x7fff7cbf3304 - _pthread_body
  48:     0x7fff7cbf626e - _pthread_start
thread 'tokio-runtime-worker-1' panicked at 'called `Result::unwrap()` on an `Err` value: "PoisonError { inner: .. }"', src/libcore/result.rs:997:5
stack backtrace:
   0:        0x106334b33 - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h9a87463918f2aff9
                               at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1:        0x1063309fc - std::sys_common::backtrace::_print::h54740e69908f9100
                               at src/libstd/sys_common/backtrace.rs:70
   2:        0x106333771 - std::panicking::default_hook::{{closure}}::h519f1fd4b67636f1
                               at src/libstd/sys_common/backtrace.rs:58
                               at src/libstd/panicking.rs:200
   3:        0x106333477 - std::panicking::default_hook::h5442e3ae9abda811
                               at src/libstd/panicking.rs:215
   4:        0x106333efe - <std::panicking::begin_panic::PanicPayload<A> as core::panic::BoxMeUp>::get::hfb37cabc364058a5
                               at src/libstd/panicking.rs:478
   5:        0x106333a1c - std::panicking::continue_panic_fmt::h3de7ba5e03709cd8
                               at src/libstd/panicking.rs:385
   6:        0x106333908 - std::panicking::try::do_call::hbdc2ad4ee791d633
                               at src/libstd/panicking.rs:312
   7:        0x106349ac1 - core::char::methods::<impl char>::escape_debug::h212c39657852eb51
                               at src/libcore/panicking.rs:85
   8:        0x10612a020 - core::result::unwrap_failed::h5690156eeacbd95e
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libcore/macros.rs:16
   9:        0x1061283a0 - <core::result::Result<T, E>>::unwrap::hcba43b53af134052
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libcore/result.rs:798
  10:        0x10613c7cc - socket::main::{{closure}}::{{closure}}::{{closure}}::h65209121397fc107
                               at src/main.rs:55
  11:        0x1061657c5 - <futures::stream::for_each::ForEach<S, F, U> as futures::future::Future>::poll::hba2ade841f2a8d80
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/stream/for_each.rs:46
  12:        0x10614374b - <futures::future::chain::Chain<A, B, C>>::poll::ha31aaa22c274a3d1
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/future/chain.rs:26
  13:        0x10616dbf4 - <futures::future::and_then::AndThen<A, B, F> as futures::future::Future>::poll::h36be6aecf2620f6e
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/future/and_then.rs:32
  14:        0x10631eed4 - std::collections::hash::table::TaggedHashUintPtr::ptr::h71c35fc2729a4cd1
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/future/mod.rs:113
  15:        0x106272154 - crossbeam_utils::backoff::Backoff::snooze::hf86b294fe90ae20d
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/task_impl/mod.rs:326
  16:        0x10627242f - crossbeam_utils::backoff::Backoff::snooze::hf86b294fe90ae20d
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/task_impl/mod.rs:396
  17:        0x106297816 - futures::task_impl::std::CURRENT_THREAD_NOTIFY::__init::h2ae73e7b705e5632
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/task_impl/std/mod.rs:78
  18:        0x106272287 - crossbeam_utils::backoff::Backoff::snooze::hf86b294fe90ae20d
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/task_impl/mod.rs:396
  19:        0x106272017 - crossbeam_utils::backoff::Backoff::snooze::hf86b294fe90ae20d
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/task_impl/mod.rs:288
  20:        0x1062720e4 - crossbeam_utils::backoff::Backoff::snooze::hf86b294fe90ae20d
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/task_impl/mod.rs:326
  21:        0x10627821c - tokio_threadpool::task::Task::run::{{closure}}::h13fe84e87d32d8e1
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.13/src/task/mod.rs:145
  22:        0x1062855dc - core::ops::function::FnOnce::call_once::ha0536114efff9727
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libcore/ops/function.rs:231
  23:        0x1062700f7 - <tokio_threadpool::task::blocking::State as core::cmp::PartialEq>::eq::hc819e761b595b012
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panic.rs:309
  24:        0x106273be4 - num_cpus::get::h40e1f130c2a5751d
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panicking.rs:297
  25:        0x10633672e - panic_unwind::dwarf::eh::read_encoded_pointer::h52da212b8b68c3fd
                               at src/libpanic_unwind/lib.rs:92
  26:        0x106273b02 - num_cpus::get::h40e1f130c2a5751d
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panicking.rs:276
  27:        0x106271dce - crossbeam_utils::backoff::Backoff::snooze::hf86b294fe90ae20d
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panic.rs:388
  28:        0x106277cd4 - tokio_threadpool::task::Task::run::haa19702dd96317b9
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.13/src/task/mod.rs:130
  29:        0x10628f3e0 - tokio_threadpool::worker::Worker::run_task2::h621496ceb1b00be9
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.13/src/worker/mod.rs:567
  30:        0x10628ed86 - tokio_threadpool::worker::Worker::run_task::h3dd0baf934cb8c94
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.13/src/worker/mod.rs:459
  31:        0x10628e949 - tokio_threadpool::worker::Worker::try_steal_task::h5bd0d0ed38bb9e0c
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.13/src/worker/mod.rs:416
  32:        0x10628dfab - tokio_threadpool::worker::Worker::try_run_task::hde136a21fb55d839
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.13/src/worker/mod.rs:301
  33:        0x10628de1a - tokio_threadpool::worker::Worker::with_current::{{closure}}::h16c61ff88e3d124f
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.13/src/worker/mod.rs:241
  34:        0x106212ae7 - tokio::runtime::threadpool::builder::Builder::build::{{closure}}::{{closure}}::{{closure}}::{{closure}}::{{closure}}::hfa5221673fe1c809
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.18/src/runtime/threadpool/builder.rs:349
  35:        0x10620e9fc - futures::task_impl::std::CURRENT_THREAD_NOTIFY::__init::h5bf5b3beb41ca2b7
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-trace-core-0.1.0/src/dispatcher.rs:54
  36:        0x106212b18 - tokio::runtime::threadpool::builder::Builder::build::{{closure}}::{{closure}}::{{closure}}::{{closure}}::h278b0929f77e2d35
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.18/src/runtime/threadpool/builder.rs:348
  37:        0x10621457d - tokio::runtime::threadpool::builder::Builder::build::{{closure}}::hb526aa791654978f
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-timer-0.2.10/src/timer/handle.rs:94
  38:        0x106213a5f - tokio::runtime::threadpool::builder::Builder::build::{{closure}}::hb526aa791654978f
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/thread/local.rs:299
  39:        0x106213187 - tokio::runtime::threadpool::builder::Builder::build::{{closure}}::hb526aa791654978f
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/thread/local.rs:245
  40:        0x106214407 - tokio::runtime::threadpool::builder::Builder::build::{{closure}}::hb526aa791654978f
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-timer-0.2.10/src/timer/handle.rs:81
  41:        0x106212b71 - tokio::runtime::threadpool::builder::Builder::build::{{closure}}::{{closure}}::{{closure}}::hb12b9d86c2ac08d8
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.18/src/runtime/threadpool/builder.rs:347
  42:        0x10621e113 - core::ptr::swap_nonoverlapping_bytes::h183454784ea0cbf4
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-timer-0.2.10/src/clock/clock.rs:141
  43:        0x10621365d - tokio::runtime::threadpool::builder::Builder::build::{{closure}}::hb526aa791654978f
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/thread/local.rs:299
  44:        0x106213128 - tokio::runtime::threadpool::builder::Builder::build::{{closure}}::hb526aa791654978f
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/thread/local.rs:245
  45:        0x10621e011 - core::ptr::swap_nonoverlapping_bytes::h183454784ea0cbf4
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-timer-0.2.10/src/clock/clock.rs:124
  46:        0x106212bc1 - tokio::runtime::threadpool::builder::Builder::build::{{closure}}::{{closure}}::hf61eb64afa1784fa
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.18/src/runtime/threadpool/builder.rs:346
  47:        0x1062148d9 - tokio_timer::timer::handle::CURRENT_TIMER::__init::h354228798f631146
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-reactor-0.1.9/src/lib.rs:237
  48:        0x106213c99 - tokio::runtime::threadpool::builder::Builder::build::{{closure}}::hb526aa791654978f
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/thread/local.rs:299
  49:        0x1062131e8 - tokio::runtime::threadpool::builder::Builder::build::{{closure}}::hb526aa791654978f
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/thread/local.rs:245
  50:        0x1062146c6 - tokio_timer::timer::handle::CURRENT_TIMER::__init::h354228798f631146
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-reactor-0.1.9/src/lib.rs:217
  51:        0x106212c56 - tokio::runtime::threadpool::builder::Builder::build::{{closure}}::h4a57c69ddb3f610b
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.18/src/runtime/threadpool/builder.rs:345
  52:        0x10627cc65 - tokio_threadpool::callback::Callback::call::he025138dcd3a1aec
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.13/src/callback.rs:22
  53:        0x10628db15 - tokio_threadpool::worker::Worker::do_run::{{closure}}::{{closure}}::h29345c31eaaae3a2
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.13/src/worker/mod.rs:127
  54:        0x106294952 - tokio_threadpool::pool::Pool::rand_usize::RNG::__getit::h7215ee2d72eccd5f
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-executor-0.1.7/src/global.rs:209
  55:        0x106284f8d - std::sync::once::Once::is_completed::h4ce41091a63ea803
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/thread/local.rs:299
  56:        0x10628429f - std::sync::once::Once::is_completed::h4ce41091a63ea803
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/thread/local.rs:245
  57:        0x10629484e - tokio_threadpool::pool::Pool::rand_usize::RNG::__getit::h7215ee2d72eccd5f
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-executor-0.1.7/src/global.rs:178
  58:        0x10628dbb6 - tokio_threadpool::worker::Worker::do_run::{{closure}}::h77bf96e795e53609
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.13/src/worker/mod.rs:125
  59:        0x106284b92 - std::sync::once::Once::is_completed::h4ce41091a63ea803
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/thread/local.rs:299
  60:        0x1062842ec - std::sync::once::Once::is_completed::h4ce41091a63ea803
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/thread/local.rs:245
  61:        0x10628da06 - tokio_threadpool::worker::Worker::do_run::h18c2123a60898136
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.13/src/worker/mod.rs:116
  62:        0x106293469 - tokio_threadpool::pool::Pool::spawn_thread::{{closure}}::h9dca92df71cbda1c
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.13/src/pool/mod.rs:344
  63:        0x106283a4f - crossbeam_epoch::collector::LocalHandle::is_pinned::h8b9d9c8f2d1f0629
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/sys_common/backtrace.rs:135
  64:        0x10627e20f - <tokio_threadpool::worker::state::Lifecycle as core::cmp::PartialEq>::eq::h219272da38dab568
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/thread/mod.rs:469
  65:        0x1062700bf - <tokio_threadpool::task::blocking::State as core::cmp::PartialEq>::eq::hc819e761b595b012
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panic.rs:309
  66:        0x106273c5c - num_cpus::get::h40e1f130c2a5751d
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panicking.rs:297
  67:        0x10633672e - panic_unwind::dwarf::eh::read_encoded_pointer::h52da212b8b68c3fd
                               at src/libpanic_unwind/lib.rs:92
  68:        0x1062739f4 - num_cpus::get::h40e1f130c2a5751d
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panicking.rs:276
  69:        0x106271d7f - crossbeam_utils::backoff::Backoff::snooze::hf86b294fe90ae20d
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/panic.rs:388
  70:        0x10627e05d - <tokio_threadpool::worker::state::Lifecycle as core::cmp::PartialEq>::eq::h219272da38dab568
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libstd/thread/mod.rs:468
  71:        0x106281d07 - core::alloc::Layout::repeat::h184f4f2b0f440f7a
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/liballoc/boxed.rs:734
  72:        0x1063361cb - std::sys::unix::thread::Thread::new::thread_start::h2ccd51efe09a6d88
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/liballoc/boxed.rs:744
                               at src/libstd/sys_common/thread.rs:14
                               at src/libstd/sys/unix/thread.rs:81
  73:     0x7fff7cbf3304 - _pthread_body
  74:     0x7fff7cbf626e - _pthread_start
#15

Ok, I think I understand it. You are listening on socket for each message and you want to send something out on target for each incoming message. Do I understand that right? So the target connection should live as long as the socket connection?

1 Like
#16

@najamelan : Yes, exactly.

#17

Ok, than for me you can’t just do TcpStream::connect inside the for_each. How does TcpStream connection know when the socket is closed? One possible solution:

Make a Sink to which you forward the Stream of socket. This struct has it’s own TcpConnection which it opens on new. You can create the sink in for_each. Now when the Stream closes, you can close the sink and manually close the tcp connection. You can probably do that in Drop, or it might even do it automatically if you have no more handles to target maybe tokio will close the connection for you. This way the duration of the target is linked to the lifetime of your struct and the lifetime of your struct is tied to the for_each block or the stream…

2 Likes
#18

Sorry, even better, I think you can create a tcp connection as a sink and just use the with method to preprocess the messages from the stream, than you don’t have to implement a sink yourself.

TcpStream does not implement Sink, but it has AsyncWrite which will be a sink if you frame it with a codec…

2 Likes
#19

@Sajjad Does that make sense?

1 Like
#20

I’m thinking about your suggestion, I can’t understand futures’s sink how can fix the problem. because I think living lua’s thread outside of the stream’s task is major problem.