Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

116
Views
Node / Express race condition on DB operations

I have an express route that needs to retrieve a row from a db, check if a field has a value set and if not set it. The row data then gets sent back to the client.

I know that node runs on a single thread but I/O operations do actually run asynchronously so I think I may have a problem if whilst the first client is waiting to write to db, a second client comes and reads a null value and performs the write a second time.

I can't have this happen as the value written is a shared value that there can only be one of.

Am I correct that this could happen and if so what is a recommended way to handle this?

Thanks.

let express = require('express');
let router = express.Router();

router.post('/getRoomStateByRoomUrl', async (req, res, next) => {
    const roomUrl = req.body.room_url;
    try {
        //READ FROM DB
        const roomState = await RoomStateModel.getRoomStateByRoomUrl(roomUrl);

        if(!roomState.tokboxSessionID) {
            const newSessionID = await TokboxService.createSession();
            
            //WRITE TO DB
            await RoomStateModel.setTokboxSessionID(newSessionID);
            
            roomState.tokboxSessionID = newSessionID;
        }
        res.status(200).json(roomState);
    } catch (error) {
        next(error);
    }
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!