英文:
What server side happen when abort a XHR request in client?
问题
抱歉,我明白您只需要翻译特定的内容。以下是您要求的翻译:
我想知道在客户端中断XHR请求时服务器端会发生什么情况,
服务器端是否仍然在运行,例如在数据库中执行事务?
英文:
I wonder what server-side will happen when aborting an XHR request in the client,
will the serverside still running, e.g do a transaction in DB?
答案1
得分: 4
通常在请求中,获取数据并返回它 - 在这种情况下,服务器只有在尝试向客户端写回数据时(由于TCP/IP协议的工作方式),才能可靠地注意到客户端已断开连接。
这很容易导致这样一种情况:客户端发出请求,服务器执行了昂贵的操作,只得知客户端不再存在,数据也被丢弃。这就是为什么在可能的情况下,流式传输结果更可取的原因之一。如果您可以避免预先收集所有数据,而是在数据变得可用时返回数据,您就不会冒着执行无用工作的风险(尽管客户端仍然可以在连接中途中止,但这是他的选择)。
英文:
Generally in a request, fetch data and return it -scenario the server can only reliably notice that the client has dropped the connection when it will try to write data back to the client (due to how the TCP/IP protocol works).
This can easily cause a scenario where the client makes a request, the server performs expensive work only to find out the client is no longer there and the data is dropped. This is one reason why streaming results are preferable when possible. If you can avoid gathering all the data up front, instead returning them as they become available, you don't risk performing useless work (although the client can still abort mid-connection, but that's his choice).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论