question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

potential racecondition?

See original GitHub issue

First 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:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
7opfcommented, Feb 9, 2021

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

0reactions
japrescottcommented, Feb 16, 2021

thanks @vkarpov15 ❤️

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found