2个并发请求在Node.js应用中混杂在一起 [英] 2 concurrent requests getting mixed up in Node.js app

查看:118
本文介绍了2个并发请求在Node.js应用中混杂在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对今天在应用程序中看到的内容完全感到困惑.

I am completely stumped by what I noticed today in my app.

我有一个用node.js编写的应用程序,该应用程序在nginx上运行,后端使用mongodb.我有一个"authenticateUser" cal,其中包含用户名和密码.然后,它查询mongodb以检索用户文档,并检查密码是否匹配.

I have an app written in node.js running on nginx with mongodb in the backend. I have an 'authenticateUser' cal which takes in a username and password. It then queries mongodb to retrieve the users document and checks if the password matches up.

我们编写了一个脚本,该脚本基本上在一个循环中调用了100次"authenticateUser".工作正常.没有错误.现在,我们从2个终端运行相同的脚本,一个用于用户账单,另一个用于用户sam.我们开始在两个终端上看到故障.我会说约有10%的请求因密码错误而失败.

We wrote a script which basically calls 'authenticateUser' in a loop 100 times. It worked fine. No errors. Now we ran the same script from 2 terminals, one for user bill and the other for user sam. We started seeing failures on both the terminals. I would say about 10% of the requests failed with invalid password errors.

当我们检查日志文件时,我们惊讶地发现Bill的用户名与sam的密码混为一谈.我们不知道发生了什么事?我们必须做一些明显错误的事情.它是什么?这两个请求不是完全隔离吗?

When we inspected the log files, we were completely surprised to see bill's username getting mixed up with sam's password. We have no idea whats going on? We must be doing something obviously wrong. What is it? Aren't the 2 requests completely isolated from each other?

非常感谢您的帮助.

非常感谢! SU

推荐答案

您是否经常使用全局变量?缺少var是此类错误的常见原因.

Do you use global variables often? Missing var is a common cause of such errors.

是的,我想看一下源代码...

And yeah, i'd like to see a source code...

这篇关于2个并发请求在Node.js应用中混杂在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆