[issue24775] Python client failing to connect to server but completing as if successful

2020-11-30 Thread Irit Katriel


Irit Katriel  added the comment:

Python 2 is past its EOL.

--
nosy: +iritkatriel
resolution:  -> out of date
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24775] Python client failing to connect to server but completing as if successful

2015-08-03 Thread R. David Murray

R. David Murray added the comment:

If whatever change fixed this has not already been backported to 2.7, it is 
likely that whatever it was was deemed to complex for backport.  If someone can 
figure out what the fix was and propose a reasonable way to back port it, we 
would most likely do so.

--
nosy: +r.david.murray

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24775] Python client failing to connect to server but completing as if successful

2015-08-01 Thread Seán Kelleher

New submission from Seán Kelleher:

I have a Go server that listens to a port, runs a Python client to connect to 
the port as a subcommand, and reads from the client. However, the client (as 
follows) will occasionally run to completion without connecting to the port, 
but without raising an exception:

import socket
import sys

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
[addr, port] = sys.argv[1].split(':')
sock.connect((addr, int(port)))
try:
sock.send("hello")
finally:
sock.close()

print "done."

`server.go` follows:

package main

import (
"log"
"net"
"os"
"os/exec"
)

func main() {
ln, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IPv4(127, 
0, 0, 1)})
if err != nil {
log.Fatalf("%v", err)
}
defer ln.Close()

cmd := exec.Command(
"python",
"client.py",
ln.Addr().(*net.TCPAddr).String(),
)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

if err := cmd.Start(); err != nil {
log.Fatalf("%v", err)
}
defer cmd.Process.Kill()

go func() {
log.Printf("command exited with: %v", cmd.Wait())
log.Printf("closing listener: %v", ln.Close())
}()

conn, err := ln.Accept()
if err != nil {
log.Fatalf("%v", err)
}

buf := make([]byte, 1024)
n, err := conn.Read(buf)
log.Println(string(buf[:n]))
}

When the connection is successful, the output is as expected:

done.
2015/08/01 21:03:50 hello

A failed connection, by contrast, gives no indication from Python that the 
command failed (`done.` is output), but it is evident that the connection was 
not established:

done.
2015/08/01 20:56:55 command exited with: 
2015/08/01 20:56:55 closing listener: 
2015/08/01 20:56:55 accept tcp4 127.0.0.1:42550: use of closed network 
connection
exit status 1

>From this, it appears as though the Python client thinks it has established a 
>connection, because neither the `connect` nor the `send` call raise an 
>exception.

This behaviour is corrected in Python 3 (all runs look like the first 
instance), so it appears to be local to Python 2.7.

--
components: Library (Lib)
messages: 247826
nosy: Seán Kelleher
priority: normal
severity: normal
status: open
title: Python client failing to connect to server but completing as if 
successful
type: behavior
versions: Python 2.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com