Skip to content
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

Sometimes it doesn't trigger the react event. #54

Open
demanuel opened this issue Jun 22, 2020 · 2 comments
Open

Sometimes it doesn't trigger the react event. #54

demanuel opened this issue Jun 22, 2020 · 2 comments

Comments

@demanuel
Copy link

demanuel commented Jun 22, 2020

I'm trying to use this library to connect to a server.

Everytime a connection is established a welcome message is sent from the server to the client. So I have the script with the following function:

sub create_sockets(Str $server,
                   Int $port,
                   Str $username,
                   Str $password,
                   Int $connections,
                   Bool $TLS,
                   Bool $insecure
                   --> List
                   ){

    my @socket_list;
    my Lock $lock = Lock.new;
    my @promises := do for 1..$connections -> $i {
        start {
            try {
                my $conn;
                if $TLS {
                    $conn = await IO::Socket::Async::SSL.connect($server, $port, :$insecure);
                } else {
                    $conn = await IO::Socket::Async.connect($server, $port);
                }

                react whenever $conn.Supply -> $line {
                    print $line;
                    if $line ~~ /200/ {
                        await $conn.print("authenticate user $username\r\n");
                    } elsif $line ~~ /381/ {
                        await $conn.print("authenticate pass $password\r\n");
                    } elsif $line ~~ /281/ {
                        done;
                    } elsif $line ~~ /481/ {
                        $*ERR.print($line);
                        $conn.close;
                        exit(1);
                    }
                }
                $lock.protect: {
                    @socket_list.push($conn);
                }
                CATCH  {
                    default {
                        $*ERR.say: "Got exception: { .Str.say; }\n{ .message }";
                        $*ERR.say: .backtrace.full;
                        .die;
                    }
                }
            }
        }
    }
    my $all_done = Promise.allof(@promises);
    await $all_done;
    return @socket_list;
}

And sometimes it hangs.

Because i have a print $line in the react i can see that when it hangs, is because 1 socket that doesn't enter the react block. This never happens with "IO::Socket::Async" (The problem is also not on the server).

I'm not sure how can i debug this. This was the best i could come up with. Is there anything wrong with that function? How can i debug this?

Thanks in advance,
David Santiago

@demanuel
Copy link
Author

demanuel commented Nov 1, 2020

Maybe it's related to rakudo/rakudo#3995 ?

@demanuel
Copy link
Author

From: https://www.nntp.perl.org/group/perl.perl6.users/2020/12/msg9555.html

There's a much better a simpler example located at https://github.com/dakkar/raku-socket-test-from-demanuel

Regards,
David Santiago

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant