geertj / gruvi

Async IO for Python, Simplified
http://gruvi.readthedocs.org/
MIT License
94 stars 12 forks source link

HttpClient does not detect closed/unopenable connection? #9

Closed jmooreoliva closed 10 years ago

jmooreoliva commented 10 years ago

This may very well be a case of my not understanding the API. Though in my defense I searched both the docs and the http tests before posting here.

Below I attempt to connect to a server that is not running. I would expect the connect call to raise some kind of exception. Instead the connection call works, and it is not until getresponse() a warning is logged and then control is never returned to the caller.

Please find the example code below along with the output for both when the server is running (which is not the error case) and when the server is not running (which is the condition I am writing this issue about).

from gruvi.http import *

import logging

import sys

#Set up a logger so that gruvi can log 
logger = logging.getLogger()
logger.setLevel(logging.INFO)
handler = logging.StreamHandler(sys.stdout)
template = '%(levelname)s %(message)s'
handler.setFormatter(logging.Formatter(template))
logger.addHandler(handler)

try:
    client = HttpClient()

    print 'connecting'
    print client.connect(('localhost', 8444))

    print 'requesting'
    print client.request('POST', '/api/v0/get_config')

    print 'reading'
    response = client.getresponse()

    print 'complete reading'

    client.close()

    print response.status
    print response.read()
except Exception:
    logging.error('Error.', exc_info=True)

==Output when server listening==

connecting
None
requesting
None
reading
complete reading
200
RESPONSE DATA HERE

==Output when server is not listening, connection should fail==

connecting
None
requesting
None
reading
WARNING [Main:Hub|HttpClient-1] pyuv error -32 in write callback
jmooreoliva commented 10 years ago

I forgot to mention: This test was run in ubuntu 12.04 with pyuv 0.11.4 and python 2.7.3.

geertj commented 10 years ago

@jmooreoliva thanks!

This was a bug and fixed in 86ba2984418984d45ed581a2209377fcb0c276ea. When you connect to an address and it fails, a TransportError will be raised now.