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

IO::Socket::INET behaving badly with Channels #4247

Closed
p6rt opened this issue May 14, 2015 · 5 comments
Closed

IO::Socket::INET behaving badly with Channels #4247

p6rt opened this issue May 14, 2015 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented May 14, 2015

Migrated from rt.perl.org#125199 (status was 'rejected')

Searchable as RT125199$

@p6rt
Copy link
Author

p6rt commented May 14, 2015

From tony.odell@live.com

CODE​:
#!/usr/bin/env perl6 use Test; my $server = IO​::Socket​::INET.new(​:localhost<127.0.0.1>, :localport(8091), :listen);my $supply = Supply.new; my $promise = start({ my $conn = $server.accept; $supply.emit($conn);}); $supply.tap(-> $conn { my $data = ''; 'Starting to receive.'.say; while my $d = $conn.recv { $data ~= $d; } 'Never gets to this line.'.say; ok $data eq 'Hello, perl6.';}); my $conn = IO​::Socket​::INET.new(​:host<127.0.0.1>, :port(8091));'Connection sending data.'.say;$conn.send('Hello, perl6.'); await $promise;


Expected​:
Starting to receiveConnection sending dataNever gets to this line


Actual​:
$conn.recv hangs waiting for data despite data having been sent to the socket
 

@p6rt
Copy link
Author

p6rt commented Oct 11, 2015

From @niner

I think, this is just a bug in the test script and not in Rakudo's Channels.
The "while my $d = $conn.recv" loop will keep running until the connection is closed because recv will block and wait for more input. However, you never close the connection in your client.
With an added $conn.close and some minor adjustments for changes in Rakudo since this bug was opened (comments inline), the following script runs and gives the intended output​:

#!/usr/bin/env perl6

use Test;

my $supply = Supply.new;

my $promise = start { # start is no function, don't call it like one
  # Rakudo prohibits calling .accept in a different thread to the one opening the connection
  my $server = IO​::Socket​::INET.new(​:localhost<127.0.0.1>, :localport(8091), :listen);
  my $conn = $server.accept;
  $supply.emit($conn);
};

$supply.tap(-> $conn {
  my $data = '';
  'Starting to receive.'.say;
  while my $d = $conn.recv {
  $data ~= $d;
  }
  'Never gets to this line.'.say;
  ok $data eq 'Hello, perl6.';
});

sleep 1; # give the server time to connect
my $conn = IO​::Socket​::INET.new(​:host<127.0.0.1>, :port(8091));
'Connection sending data.'.say;
$conn.print("Hello, perl6.");
$conn.close;

await $promise;

@p6rt
Copy link
Author

p6rt commented Oct 11, 2015

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Oct 11, 2015

@niner - Status changed from 'open' to 'rejected'

@p6rt p6rt closed this as completed Oct 11, 2015
@p6rt
Copy link
Author

p6rt commented Oct 12, 2015

From tony.odell@live.com

Changing the script to not exploit the bug doesn't make the bug go away. I don't see anywhere that rakudo doesn't support this, I know there is a bug on moarvm where they're discussing handle passing between threads being the issue

Sent from Outlook

On Sun, Oct 11, 2015 at 4​:23 AM -0700, "Stefan Seifert via RT" <perl6-bugs-followup@​perl.org> wrote​:
I think, this is just a bug in the test script and not in Rakudo's Channels.
The "while my $d = $conn.recv" loop will keep running until the connection is closed because recv will block and wait for more input. However, you never close the connection in your client.
With an added $conn.close and some minor adjustments for changes in Rakudo since this bug was opened (comments inline), the following script runs and gives the intended output​:

#!/usr/bin/env perl6

use Test;

my $supply = Supply.new;

my $promise = start { # start is no function, don't call it like one
  # Rakudo prohibits calling .accept in a different thread to the one opening the connection
  my $server = IO​::Socket​::INET.new(​:localhost<127.0.0.1>, :localport(8091), :listen);
  my $conn = $server.accept;
  $supply.emit($conn);
};

$supply.tap(-> $conn {
  my $data = '';
  'Starting to receive.'.say;
  while my $d = $conn.recv {
  $data ~= $d;
  }
  'Never gets to this line.'.say;
  ok $data eq 'Hello, perl6.';
});

sleep 1; # give the server time to connect
my $conn = IO​::Socket​::INET.new(​:host<127.0.0.1>, :port(8091));
'Connection sending data.'.say;
$conn.print("Hello, perl6.");
$conn.close;

await $promise;

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant