2012-03-29 19 views
5

Sto eseguendo un server cherrypy 3.2.0 con Python 2.5.1, che dà il seguente errore ogni pochi giorni su qualsiasi istruzione dall'interfaccia utente fino a quando non viene ucciso e riavviato: -cherrypy/dev/urandom (o equivalente) non trovato - errore

[29/Mar/2012:06:37:57] HTTP Traceback (most recent call last): 
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/_cprequest.py", line 636, in respond 
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/_cprequest.py", line 97, in run 
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/_cprequest.py", line 57, in __call__ 
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/lib/sessions.py", line 757, in init 
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/lib/sessions.py", line 162, in __init__ 
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/lib/sessions.py", line 190, in _regenerate 
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/lib/sessions.py", line 204, in generate_id 
File "/usr/lib/python2.5/site-packages/CherryPy-3.2.0-py2.5.egg/cherrypy/_cpcompat.py", line 264, in random20 
File "/usr/lib/python2.5/os.py", line 733, in urandom 
NotImplementedError: /dev/urandom (or equivalent) not found 

_cpcompat.py ha seguente pezzo di codice che suggerisce che v'è un ripiego su random.random nel caso in cui CherryPy non è in grado di leggere /dev/urandom, ma non sembra essere ricadere su di essa.

try: 
    os.urandom(20) 
    import binascii 
    def random20(): 
     return binascii.hexlify(os.urandom(20)).decode('ascii') 

except (AttributeError, NotImplementedError): 
    import random 
    # os.urandom not available until Python 2.4. Fall back to random.random. 
    def random20(): 
     return sha('%s' % random.random()).hexdigest() 

seguito è il frammento di codice da os.py, rilevante nel contesto: -

if not _exists("urandom"):

def urandom(n): 
     """urandom(n) -> str 

     Return a string of n random bytes suitable for cryptographic use. 

     """ 
     try: 
      _urandomfd = open("/dev/urandom", O_RDONLY) 
     except (OSError, IOError): 
      raise NotImplementedError("/dev/urandom (or equivalent) not found") 
     bytes = "" 
     while len(bytes) < n: 
      bytes += read(_urandomfd, n - len(bytes)) 
     close(_urandomfd) 
     return bytes 

Allo stesso tempo, quando cherrypy non è in grado di leggere /dev/urandom, il seguente frammento di codice sta lavorando bene: -

python -c "import os;fd = open('/dev/urandom', 'r');print fd.read(5);fd.close()"

ho due domande: -

  1. Perché cherrypy gettando errore non implementato quando sono in grado di leggere bit casuali da/dev/urandom
  2. Perché _cpcompact.py non esecuzione del tranne quando parte os.py sta sollevando NotImplementedError.
+0

fa ' python -c "import os; print os.urandom (5) "' lavoro? – tMC

+0

purtroppo, lo fa, mentre cherrypy dice/dev/urandom non implementato! – haltTm

+0

Forse le autorizzazioni sono rovinate da qualche parte? – sdolan

risposta

4

Questa non è una risposta, tuttavia, nella mia esperienza questo NotImplementedError è errato ma compare quando "troppi file" sono errori aperti che iniziano a mostrare dopo che un processo di multiprocessing inizia a lanciare un'eccezione non rilevata, rimane in sospeso per sempre nei thread figli o nei processi figli.

vorrei iniziare il debug più in alto nello stack e vedere se ci sono sepolti o eccezioni silenziose lanciate da un processo

Ecco un esempio del mio stack trace quando comincio a vedere questo errore

Exception in thread Plotter: 
Traceback (most recent call last): 
    File "threading.pyc", line 532, in __bootstrap_inner 
    File "plotters/edge.pyc", line 459, in run 
    AttributeError: 'error' object has no attribute 'error' 

OSError: [Errno 24] Too many open files 
    File "multiprocessing/connection.pyc", line 150, in Client 
    File "multiprocessing/connection.pyc", line 370, in deliver_challenge 
    None 
    File "os.pyc", line 756, in urandom 
NotImplementedError: /dev/urandom (or equivalent) not found 

mio Prodotto dall'errore AttributeError, alla fine ... l'errore/urandom non trovato imlp

1

Questa non è una risposta, ma forse si potrebbe mettere un po 'di codice di debug in os.py (non riesco a immaginare che avrebbe un impatto di qualsiasi altro programma che utilizza import os ma vale la pena ricordare la sua personalizzata)

if not _exists("urandom"): 
    def urandom(n): 
     """urandom(n) -> str 

     Return a string of n random bytes suitable for cryptographic use. 

     """ 
     try: 
      _urandomfd = open("/dev/urandom", O_RDONLY) 
     # debug changes 
     except (OSError, IOError) as Err: 
      import syslog 
      syslog.syslog(repr(Err)) 
     # /debug 
      raise NotImplementedError("/dev/urandom (or equivalent) not found") 
     bytes = "" 
     while len(bytes) < n: 
      bytes += read(_urandomfd, n - len(bytes)) 
     close(_urandomfd) 
     return bytes 

Speriamo che questo ti dica esattamente quale sia l'errore. (Naturalmente puoi sostituire syslog semplicemente scrivendo in un file, ecc.)

+0

Una cosa che possiamo concludere è 'OSError' o 'IOError'. Questo getta luce sul tipo di errore? Condividerò i risultati con te quando accadrà l'errore. Un'altra preoccupazione importante è, perché '_cpcompat.py' non sta eseguendo la parte eccedente, cioè, 'importa casuale ...' – haltTm

+0

l'eccezione' OSError' o 'IOError' può essere utilizzata per rappresentare qualsiasi errore di sistema numerico. L'oggetto di eccezione che viene generato contiene l'errno specifico che sarebbe davvero utile (permesso negato, file non trovato, handle non aperto per la lettura, ecc. Ecc.). Questo è ciò che deve essere catturato per capire meglio cosa sta succedendo. – tMC

+0

Puoi aiutarmi con la versione python 2.5 di 'except (OSError, IOError) come Err'. Al momento, sto facendo 'except Exception, e:' invece, che dovrebbe servire allo stesso scopo, immagino. – haltTm

0

Se il sistema non ha già creato/dev/random e/dev/urandom, possono essere creati con i seguenti comandi:

mknod -m 644/dev/random c 1 8

mknod -m 644/dev/urandom c 1 9

chown root: root/dev/random/dev/urandom

+0

Sul mio sistema la mod è 666. –