(大)文件上传时连接重置
因此,我在 Pylons 中的文件上传方面遇到了一个相当令人烦恼的问题,我希望有人能够帮助我。最初我在这里发布了这个问题,认为这是一个Pylons 的问题,但我后来得出结论,问题是由于服务器(即粘贴)引起的,并且我已经准确地追踪到问题发生的位置,但不确定如何解决它。行为如下。我有一个 Pylons Web 应用程序,我通过 Paster 提供服务。该应用程序的一部分允许用户将文件上传到系统,有时这些文件可能相当大(> 50mb)。在此类上传期间,服务器偶尔会重置连接(即,在 Chrome 中,错误显示为“错误 101 (net::ERR_CONNECTION_RESET):连接已重置。”。)这种情况并不总是发生,只是对于较大的文件,大约有 50% 的时间会出现这种情况。
在这些情况下,服务器永远不会将 POST 交给应用程序级别。没有抛出异常(至少我能找到)。我已将问题范围缩小到cascade.py(特别是从httpserver.py 调用的wsgi_application 方法)。从后者来看:
结果 = self.server.wsgi_application(self.wsgi_environ, self.wsgi_start_response)
在cascade.py的call函数中,该文件似乎被写入临时文件。相关循环开始于:
当copy_len>时0:
然后将块一一写入打开的文件中。这些单独的写入都不会引发异常。然而,服务器通常会在这些写入过程中简单地“消失”,看似随机(时间似乎与此无关)。因此,如果我打印出正在递减的 copy_len 大小,我会看到它减少到一定程度,然后服务器突然发送“连接重置”(或者至少客户端认为是这样)和该方法似乎已退出(copy_len 停止打印,就好像循环已退出,尽管它不是 0)。
我完全被难住了,因为 1)这只是偶尔发生,2)我似乎无法追踪实际的错误/异常——它只是......死了。
如果重要的话,我正在运行paste 1.7.3、Python 2.7 和Fedora OS。有谁知道可能发生的情况以及我如何解决这个问题?非常感谢您的帮助。
So I'm having a rather vexing issue with file uploads in Pylons that I'm hoping someone might be able to assist me with. Originally I posted the issue here thinking this was an issue with Pylons, but I've since come to conclude that the issue is due to the server, i.e., paste, and I've tracked down exactly where the issue occurs, but am unsure how to resolve it. The behavior is as follows. I have a Pylons web application that I'm serving via paster. One piece of the application allows for users to upload files to the systems, and sometimes these can be rather big (> 50mb). During such uploads, the server sporadically resets the connection (i.e., in Chrome the error reads "Error 101 (net::ERR_CONNECTION_RESET): The connection was reset.".) This does not always occur, only about ~50% of the time with larger files.
On these cases, the server never hands the POST up to the application level. No Exception is thrown (at least, that I can find). I've narrowed the issue down to cascade.py (in particular, the wsgi_application method invoked from httpserver.py). From the latter:
result = self.server.wsgi_application(self.wsgi_environ, self.wsgi_start_response)
In the call function of cascade.py, the file appears to be written to a temporary file. The relevant loop begins at:
while copy_len > 0:
It then writes chunks one by one to the open file. None of these writes individually throws an exception. However, the server will often simply 'go away' during these writes, seemingly at random (time does not seem to be correlated with this, either). So if I print out the copy_len size, which is being decremented, I watch it decrease up to a point, and then the server all of a sudden sends a 'connection reset' (or at least the client thinks it does) and the method seems to be exited (the copy_len ceases to be printed, as if the loop has been exited, though it was not at 0).
I'm completely stumped, as 1) this only happens sporadically, and 2) I can't seem to track down an actual error/Exception -- it just sort of... dies.
If it matters, I'm running paste 1.7.3, Python 2.7 and Fedora OS. Does anyone have any insight into what might be happening, and how I might be able to resolve this? Thank you very much for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想到了两个想法...
Two ideas come to mind ...
我在 Ubuntu 10.04 上使用 apache 2.2 + mod_python 3.3 没有问题。我已成功上传大文件(400mb)。
我使用 uploader 来构建 html 上传表单。
I've no problem using apache 2.2 + mod_python 3.3 on Ubuntu 10.04. I've succesfully uploaded big files (400mb).
I've used uploader to build the html upload form.