potential racecondition?
See original GitHub issueFirst off, thanks for creating another awesome lib @vkarpov15 😃
I am seeing some sort of racecondition but have troubles spotting it reliably why its happening (or if this has nothing to do with awaitjs/express).
Following is an abstraction of what I am doing.
Generally what I want is to have multiple different files, each with a Router from @awaitjs/express that are then put together like the following;
//tags.ts
export const tagsRouter = Router({ mergeParams: true });
tagsRouter.getAsync('/*', async (req, res) => {
console.log('Tag routes..')
await new Promise<void>((resolve) => {
setTimeout(resolve, 5000)
})
console.log('Tags finished..')
next()
})
tagsRouter.getAsync('/*', async (req, res) => {
const data = await something()
console.log('Do Tag..')
res.json(data)
})
// more routes...
//models.ts
export const modelsRouter = Router({ mergeParams: true });
modelsRouter.getAsync('/*', async (req, res) => {
console.log('Model routes..')
await new Promise<void>((resolve) => {
setTimeout(resolve, 5000)
})
console.log('Models finished..')
next()
})
// more routes...
//main.ts
import {tagsRouter} from 'tags'
import {modelsRouter} from 'models'
import {ensureAccess} from '../access';
export const mainRouter = Router({ mergeParams: true });
mainRouter.use(':userId/*', ensureAccess); //some access control which makes a async call to the database
mainRouter.use(':userId/tags', tagsRouter);
mainRouter.use(':userId/models', modelsRouter);
When running this from time to time I get the outputs in a wrong order
Tag routes..
Do Tag..
Tags Finished..
instead of
Tag routes..
Tags Finished..
Do Tag..
Am I messing something up in my setup? Am I misunderstanding this library?
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
multithreading - What is a race condition? - Stack Overflow
A race condition occurs when two or more threads can access shared data and they try to change it at the same time....
Read more >What is a Race Condition? | Baeldung on Computer Science
By definition, a race condition is a condition of a program where its behavior depends on relative timing or interleaving of multiple threads...
Read more >Race condition - Wikipedia
A race condition or race hazard is the condition of an electronics, software, or other system where the system's substantive behavior is dependent...
Read more >Race conditions and deadlocks - Visual Basic - Microsoft Learn
A race condition occurs when two threads access a shared variable at the same time. The first thread reads the variable, and the...
Read more >What is a Race Condition? - Veracode
What Is a Race Condition Vulnerability? · Interference by an untrusted process - The attacker inserts a piece of code in between the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’ve also run into this issue and confirm @EvanSmith-git branch fixes it in our tests.
thanks @vkarpov15 ❤️