Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

connectTo hangs forever #14

Closed
sdroege opened this issue Sep 9, 2014 · 3 comments
Closed

connectTo hangs forever #14

sdroege opened this issue Sep 9, 2014 · 3 comments

Comments

@sdroege
Copy link

sdroege commented Sep 9, 2014

Hi,

when using connectTo in a simple test application like the following, it hangs forever. Running with strace shows that something weird is going on with polling. In a bigger application of mine it all works though, so it's probably a race condition somewhere or something else is needed? This reliably always fails on two different Linux systems here.

{-# LANGUAGE OverloadedStrings #-}                                                                           

import Network.Connection
import Network.Socket (PortNumber (PortNum))

main :: IO ()
main = do
    ctx <- initConnectionContext
    let params = ConnectionParams "google.com" (PortNum 80) Nothing Nothing

    c <- connectTo ctx params

    connectionClose c
@sdroege
Copy link
Author

sdroege commented Sep 9, 2014

$ strace ./test
[...]
recvfrom(3, "\230\263\201\200\0\1\0\1\0\0\0\0\6google\3com\0\0\34\0\1\300\f\0\34"..., 1764, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("172.28.128.1")}, [16]) = 56
close(3) = 0
open("/etc/gai.conf", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=2584, ...}) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=2584, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f7a40568000
read(3, "# Configuration for getaddrinfo("..., 4096) = 2584
read(3, "", 4096) = 0
close(3) = 0
munmap(0x7f7a40568000, 4096) = 0
futex(0x7f7a3f38ff64, FUTEX_WAKE_PRIVATE, 2147483647) = 0
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(20480), sin_addr=inet_addr("64.15.113.39")}, 16) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(45726), sin_addr=inet_addr("172.28.129.38")}, [16]) = 0
connect(3, {sa_family=AF_UNSPEC, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(20480), sin_addr=inet_addr("64.15.113.35")}, 16) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(46867), sin_addr=inet_addr("172.28.129.38")}, [16]) = 0
connect(3, {sa_family=AF_UNSPEC, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(20480), sin_addr=inet_addr("64.15.113.50")}, 16) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(46917), sin_addr=inet_addr("172.28.129.38")}, [16]) = 0
connect(3, {sa_family=AF_UNSPEC, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(20480), sin_addr=inet_addr("64.15.113.29")}, 16) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(50577), sin_addr=inet_addr("172.28.129.38")}, [16]) = 0
connect(3, {sa_family=AF_UNSPEC, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(20480), sin_addr=inet_addr("64.15.113.54")}, 16) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(46491), sin_addr=inet_addr("172.28.129.38")}, [16]) = 0
connect(3, {sa_family=AF_UNSPEC, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(20480), sin_addr=inet_addr("64.15.113.25")}, 16) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(45980), sin_addr=inet_addr("172.28.129.38")}, [16]) = 0
connect(3, {sa_family=AF_UNSPEC, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(20480), sin_addr=inet_addr("64.15.113.45")}, 16) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(50726), sin_addr=inet_addr("172.28.129.38")}, [16]) = 0
connect(3, {sa_family=AF_UNSPEC, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(20480), sin_addr=inet_addr("64.15.113.24")}, 16) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(39382), sin_addr=inet_addr("172.28.129.38")}, [16]) = 0
connect(3, {sa_family=AF_UNSPEC, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(20480), sin_addr=inet_addr("64.15.113.49")}, 16) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(44316), sin_addr=inet_addr("172.28.129.38")}, [16]) = 0
connect(3, {sa_family=AF_UNSPEC, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(20480), sin_addr=inet_addr("64.15.113.20")}, 16) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(46322), sin_addr=inet_addr("172.28.129.38")}, [16]) = 0
connect(3, {sa_family=AF_UNSPEC, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(20480), sin_addr=inet_addr("64.15.113.30")}, 16) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(32960), sin_addr=inet_addr("172.28.129.38")}, [16]) = 0
connect(3, {sa_family=AF_UNSPEC, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(20480), sin_addr=inet_addr("64.15.113.34")}, 16) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(46053), sin_addr=inet_addr("172.28.129.38")}, [16]) = 0
connect(3, {sa_family=AF_UNSPEC, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(20480), sin_addr=inet_addr("64.15.113.44")}, 16) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(43319), sin_addr=inet_addr("172.28.129.38")}, [16]) = 0
connect(3, {sa_family=AF_UNSPEC, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(20480), sin_addr=inet_addr("64.15.113.55")}, 16) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(40255), sin_addr=inet_addr("172.28.129.38")}, [16]) = 0
connect(3, {sa_family=AF_UNSPEC, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(20480), sin_addr=inet_addr("64.15.113.40")}, 16) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(56623), sin_addr=inet_addr("172.28.129.38")}, [16]) = 0
connect(3, {sa_family=AF_UNSPEC, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(20480), sin_addr=inet_addr("64.15.113.59")}, 16) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(42982), sin_addr=inet_addr("172.28.129.38")}, [16]) = 0
close(3) = 0
socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET6, sin6_port=htons(20480), inet_pton(AF_INET6, "2a00:1450:4014:80b::1005", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = -1 ENETUNREACH (Network is unreachable)
close(3) = 0
socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 3
fcntl(3, F_GETFL) = 0x2 (flags O_RDWR)
fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(20480), sin_addr=inet_addr("64.15.113.39")}, 16) = -1 EINPROGRESS (Operation now in progress)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL) = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
timer_settime(0, 0, {it_interval={0, 0}, it_value={0, 0}}, NULL) = 0
rt_sigreturn() = -1 EINTR (Interrupted system call)
select(4, [], [3], NULL, NULL
[at this point no further new lines]

@vincenthz
Copy link
Owner

very likely you're trying to connect to the wrong port 20480 instead of the port 80. Sadly the network package is terrible, and PortNumber's "content" is supposed to be in network endianness instead of host endianness.

Instead of using 'PortNumber' you should use 'fromIntegral' which will transform the port you want to network endianness.

I'm not sure why you don't get a connection refused or timeout eventually, but this has probably something to do with the network package itself, not connection.

@sdroege
Copy link
Author

sdroege commented Sep 9, 2014

Indeed, sorry for the noise

@sdroege sdroege closed this as completed Sep 9, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants