Giter VIP home page Giter VIP logo

Comments (9)

BurntSushi avatar BurntSushi commented on June 27, 2024

Could you please provide a minimal code example that reproduces the bug?

Please provide as many details as possible, otherwise it's hard to help you.

from chan.

szagi3891 avatar szagi3891 commented on June 27, 2024

Can I give you a link to the entire repository? ( https://github.com/szagi3891/testhttp , branch "process")

In the evening I will try to extract a small piece of code.

from chan.

BurntSushi avatar BurntSushi commented on June 27, 2024

I really don't have the time to be looking through an entire repository of code. If there's a bug in chan, then I'd really prefer to see a small piece of code that I can run that reproduces the problem you're experiencing.

from chan.

szagi3891 avatar szagi3891 commented on June 27, 2024

Sure. In the evening I will try to prepare a small piece of code.

from chan.

szagi3891 avatar szagi3891 commented on June 27, 2024

I create test repo width minimal code.
Enough to do :

git clone https://github.com/szagi3891/test_chan_bug
cd test_chan_bug
cargo run

I get output :

grzegorz@grzegorz:~/Pulpit/rust/testchan$ cargo run
     Running `target/debug/testchan`
Hello, world!
before send
^CTermination signal catched.

grzegorz@grzegorz:~/Pulpit/rust/testchan$ Shutting down!

grzegorz@grzegorz:~/Pulpit/rust/testchan$ 
grzegorz@grzegorz:~/Pulpit/rust/testchan$ cargo run
     Running `target/debug/testchan`
Hello, world!
before send
worker 1: get value rx_request Some("simple value1")
^CTermination signal catched.
grzegorz@grzegorz:~/Pulpit/rust/testchan$ ./target/debug/testchan 
Hello, world!
before send
^CTermination signal catched.
Shutting down!
grzegorz@grzegorz:~/Pulpit/rust/testchan$ ./target/debug/testchan 
Hello, world!
before send
^CTermination signal catched.
Shutting down!
grzegorz@grzegorz:~/Pulpit/rust/testchan$ 
grzegorz@grzegorz:~/Pulpit/rust/testchan$ 
grzegorz@grzegorz:~/Pulpit/rust/testchan$ ./target/debug/testchan 
Hello, world!
before send
^CTermination signal catched.
Shutting down!
grzegorz@grzegorz:~/Pulpit/rust/testchan$ 
grzegorz@grzegorz:~/Pulpit/rust/testchan$ 
grzegorz@grzegorz:~/Pulpit/rust/testchan$ ./target/debug/testchan 
Hello, world!
before send
worker 9: get value rx_request Some("simple value1")
worker 7: get value rx_request Some("simple value2")
after send
before send
^CTermination signal catched.
Shutting down!
grzegorz@grzegorz:~/Pulpit/rust/testchan$

Code stops when we pass the data on channel tx_request.
Sender should never pause because the channel is asynchronous.

            println!("before send");
            tx_request.send("simple value1");
            tx_request.send("simple value2");
            tx_request.send("simple value3");
            println!("after send");

from chan.

szagi3891 avatar szagi3891 commented on June 27, 2024

description is good? I left only a small piece of code that deals with the problem.

from chan.

BurntSushi avatar BurntSushi commented on June 27, 2024

@szagi3891 Yes, thank you! I was able to trim it down to this:

#[macro_use]
extern crate chan;

use std::io;
use std::thread::{self, JoinHandle};
use std::time::Duration;

fn main() {
    println!("Hello, world!");

    let (send1, recv1) = chan::async();

    thread::spawn(move || {
        loop {
            println!("before send");
            send1.send("simple value1");
            send1.send("simple value2");
            send1.send("simple value3");
            println!("after send");

            thread::sleep(Duration::from_millis(50));
        }
    });

    let (_send2, recv2) = chan::async::<String>();

    for i in 0..30 {
        let recv1 = recv1.clone();
        let recv2 = recv2.clone();

        spawn(format!("worker {}", i), move || {
            println!("starting worker {}", i);
            loop {
                chan_select! {
                    recv1.recv() -> val => {
                        println!("worker {}: get value recv1 {:?}", i, val);
                    },
                    recv2.recv() -> val => {
                        println!("worker {}: get value recv2 {:?}", i, val);
                    }
                }
            }
        }).unwrap();
    }
    chan_select! {}
}

fn spawn<F, T>(name: String, block: F) -> io::Result<JoinHandle<T>>
    where F: FnOnce() -> T + Send + 'static, T: Send + 'static {

    thread::Builder::new().name(name).spawn(block)
}

My thinking right now is that it probably is indeed a bug. My guess is that chan_select! is for some reason not releasing a lock that all channels must acquire when sending values.

For what it's worth, I would, in general, recommend using synchronous channels, with a buffer if needed. (That doesn't help in this case though, since it looks like synchronous channels are affected too.)

from chan.

szagi3891 avatar szagi3891 commented on June 27, 2024

Thank you. And is there a chance that it will somehow fix soon?

from chan.

szagi3891 avatar szagi3891 commented on June 27, 2024

Clever amendment :)

I did own implementation channels (no macro select).
https://github.com/szagi3891/channels_async-rs

from chan.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.