views:

219

answers:

1

Hey, any idea about what is the timeout error which I am getting here:

Error trace:

  File "/array/purato/python2.6/lib/python2.6/site-packages/cherrypy/_cprequest.py", line 606, in respond                                                        
    cherrypy.response.body = self.handler()                                                                                                                      
  File "/array/purato/python2.6/lib/python2.6/site-packages/cherrypy/_cpdispatch.py", line 25, in __call__                                                       
    return self.callable(*self.args, **self.kwargs)                                                                                                              
  File "sync_server.py", line 853, in put_file                                                                                                                   
    return RequestController_v1_0.put_file(self, *args, **kw)                                                                                                    
  File "sync_server.py", line 409, in put_file                                                                                                                   
    saved_path, tgt_path, root_folder = self._save_file(client_id, theFile)                                                                                      
  File "sync_server.py", line 404, in _save_file                                                                                                                 
    saved_path, tgt_path, root_folder = get_posted_file(cherrypy.request, 'theFile', staging_path)                                                               
  File "sync_server.py", line 1031, in get_posted_file                                                                                                           
    , keep_blank_values=True)                                                                                                                                    
  File "/array/purato/python2.6/lib/python2.6/cgi.py", line 496, in __init__                                                                                     
    self.read_multi(environ, keep_blank_values, strict_parsing)                                                                                                  
  File "/array/purato/python2.6/lib/python2.6/cgi.py", line 620, in read_multi                                                                                   
    environ, keep_blank_values, strict_parsing)                                                                                                                  
  File "/array/purato/python2.6/lib/python2.6/cgi.py", line 498, in __init__                                                                                     
    self.read_single()                                                                                                                                           
  File "/array/purato/python2.6/lib/python2.6/cgi.py", line 635, in read_single                                                                                  
    self.read_lines()                                                                                                                                            
  File "/array/purato/python2.6/lib/python2.6/cgi.py", line 657, in read_lines                                                                                   
    self.read_lines_to_outerboundary()                                                                                                                           
  File "/array/purato/python2.6/lib/python2.6/cgi.py", line 685, in read_lines_to_outerboundary                                                                  
    line = self.fp.readline(1<<16)                                                                                                                               
  File "/array/purato/python2.6/lib/python2.6/site-packages/cherrypy/wsgiserver/__init__.py", line 206, in readline                                              
    data = self.rfile.readline(size)                                                                                                                             
  File "/array/purato/python2.6/lib/python2.6/site-packages/cherrypy/wsgiserver/__init__.py", line 868, in readline                                              
    data = self.recv(self._rbufsize)                                                                                                                             
  File "/array/purato/python2.6/lib/python2.6/site-packages/cherrypy/wsgiserver/__init__.py", line 747, in recv                                                  
    return self._sock.recv(size)                                                                                                                                 
timeout: timed out

Here is the code which is getting called:

    def get_posted_file(request, form_field_name, tgt_folder, tgt_fname=None):                                                                                       
        logger.debug('get_posted_file: %s' % request.headers['Last-Modified'])                                                                                       

        lowerHeaderMap = {}                                                                                                                                          
        for key, value in request.headers.items():                                                                                                                   
            lowerHeaderMap[key.lower()] = value                                                                                                                      

--->    dataDict = TmpFieldStorage(fp=request.rfile, headers=lowerHeaderMap, environ={'REQUEST_METHOD':'POST'}                                                       
                                   , keep_blank_values=True)

and:

class TmpFieldStorage(cgi.FieldStorage):                                                                                                                         
    """                                                                                                                                                          
    Use a named temporary file to allow creation of hard link to final destination                                                                               
    """                                                                                                                                                          
    def make_file(self, binary=None):                                                                                                                            
        tmp_folder = os.path.join(get_filer_root(cherrypy.request.login), 'sync_tmp')                                                                            
        if not os.path.exists(tmp_folder):                                                                                                                       
            os.makedirs(tmp_folder)                                                                                                                              
        return tempfile.NamedTemporaryFile(dir=tmp_folder)
A: 

environ={'REQUEST_METHOD':'POST'}

That seems a rather deficient environ. The CGI spec requires many more environment variables to be in there, some of which the cgi module is going to need.

In particular there is no CONTENT_LENGTH header. Without it, cgi is defaulting to reading the entire contents of the stream up until EOF. But since it is (probably) a network stream rather than a file there will be no EOF (or at least not one directly at the end of the submission), so the form reader will be sitting there waiting for more input that will never come. Timeout.

bobince
The CONTENT_LENGTH header will need to be set in environ only if it's not present in the headers. In his case I'm guessing it's already there.
Sushant