Opened 10 years ago

Closed 10 years ago

#3522 defect closed duplicate (duplicate)

getHostByName bug: "Please only pass IPs to write(), not hostnames"

Reported by: palo Owned by:
Priority: normal Milestone:
Component: names Keywords: dns hostname names ip getHostByName block blocking udp
Cc: Branch:



it seems there is a bug in t.n.c.Resolver.getHostByName():

from twisted.internet import reactor
from twisted.names.client import Resolver
from twisted.internet.defer import DeferredList

DOMAIN_NAMES = ('', '', '', '')

def cb(result):
    print 'in cb()'
    print 'result:', result

def gotError(failure):
    print 'in gotError'

def finished(result):

r = Resolver(servers=[('', 53)])
dlist = []

for domain in DOMAIN_NAMES:
    d = r.getHostByName(domain)
    d.addCallbacks(cb, gotError)

dl = DeferredList(dlist)

results in:

/usr/lib/python2.5/site-packages/Twisted-8.1.0-py2.5-linux-i686.egg/twisted/names/ DeprecationWarning: Please only pass IPs to write(), not hostnames
  self.transport.write(message.toStr(), address)
in cb()
in cb()
in cb()
in cb()

If I put a print statement in, printing the address, I get this:

('', 53)
('', 53)
('', 53)
('', 53)
('', 53)
/usr/lib/python2.5/site-packages/Twisted-8.1.0-py2.5-linux-i686.egg/twisted/names/ DeprecationWarning: Please only pass IPs to write(), not hostnames
  self.transport.write(message.toStr(), address)
('', 53)
('', 53)
('', 53)

Why is there only one warning? I think it should be 3, because there're 3 domain names.

There is even already a ticket and a patch: Ticket #2850
(but unfortunately the patch doesn't seems to work).

From the ticket:

"In addition, self.socket.sendto(datagram, addr) will call socket.gethostbyname(addr), but this call is block."

Are the dns request of the script above blocking? How can I test this?

Btw, can someone tell me where I can find the source code of reactor.connectTCP?
(I want to look how connectTCP resolves domain names).

help(twisted.internet.reactor.connectTCP) says:

"look at twisted.internet.interfaces.IReactorTCP.connectTCP"

But there is *nothing* but a doc string.

Thank you very much.


PS: Sorry for my bad english

Change History (4)

comment:1 Changed 10 years ago by Glyph

Resolution: invalid
Status: newclosed

This is just how the Python warnings system works. Normally, if the same warning is emitted multiple times, it will only be displayed the first time. You can ask Python to emit warnings multiple times with the -Walways command-line switch, or by calling warnings.filterwarnings("always").

comment:2 Changed 10 years ago by palo

Resolution: invalid
Status: closedreopened

Thanks for the fast reply, but this bug report wasn't about the number of occurrences of the warnings (that was just a side note). It was about *the reason* of the warnings. I think this warnings aren't there without a reason (otherwise they should be disabled).

I think instead of throwing this warning twisted should try to resolve the host to a IP, wouldn't that be better? In the other bug report wangminghua wrote, otherwise self.socket.sendto(datagram, addr) will call socket.gethostbyname(addr) and this would block the whole application. Is that true?

comment:3 Changed 10 years ago by Glyph

Resolution: duplicate
Status: reopenedclosed

Aah, sorry for closing as invalid, I misunderstood your complaint. This is entirely a valid bug. Unfortunately I am still going to close it :), since as you say - there's already a ticket. Please feel free to attach more information to #2850.

Also, if I've misunderstood yet again and this is reporting a different problem than #2850, go ahead and reopen with an explanation of the difference.

comment:4 Changed 8 years ago by <automation>

Owner: Jean-Paul Calderone deleted
Note: See TracTickets for help on using tickets.