Questions tagged [race-condition]
A race condition is when multiple threads/processes/clients all use a resource, without proper use of locks.
2,287
questions
0
votes
0
answers
24
views
Unable to use observable value in nested httpservice.get call - race condition
I am getting some strange issue, I have 2 http axios calls,
Call 1: POST: this call return stateId
Call 2: GET : this call uses stateId and returns cities of that particular state
const cities = this....
0
votes
2
answers
64
views
Where to await to avoid race conditions and not block the Main thread?
I have recently started using async/await (in an existing, Non Swift-UI codebase).
Two things that I haven't been able to get an answer to (neither by reading nor experimenting) is whether its wrong ...
0
votes
1
answer
31
views
Exception thrown tied to race condition issue in java program using @Transaction and @Async annotations for transaction management
I am using springboot with JdbcTemplate for persistence. I have a series of separate database steps that must be orchestrated properly as an atomic transaction. However, there is one highly time-...
0
votes
0
answers
51
views
User get cookies owned by others when using SpringSession and redis?
Recently, i wrote a block of codes which make RequestAttributes visible to other threads which caused user get cookies owned by others in staging enviroment.
I don't know what exactly happened after ...
3
votes
1
answer
25
views
Is Window.postMessage susceptible to race conditions?
MDN's examples for Window.postMessage include:
const popup = window.open(/* popup details */);
// When the popup has fully loaded, if not blocked by a popup blocker:
// This does nothing, assuming ...
0
votes
0
answers
27
views
What is the correct structure for ZIO application
I am working on an ZIO application. This is not probably the most idiomatic implementation. I am interested in knowing:
1. What is the usual design pattern for this
2. How can it be done following my (...
0
votes
1
answer
25
views
How do I ensure an API highlights text while the user simultaneously is editing that text?
On our web app, we have a textarea where we process user input and highlight certain text (similar to MS Word, Grammarly, etc.). We make an API call to the back-end, and it processes the text and ...
0
votes
1
answer
60
views
How to prevent Race Conditions using React Query?
I am new to React Query and I am trying to use the library to prevent race condition in my app.
I have a component that receives id as a prop and fetches the data accordingly and I am fetching the ...
1
vote
2
answers
37
views
Issue with async SQLite statement execution wrapper functions
I am having an issue executing an SQL statement immediately after creating and populating a table.
I think the record does not exist, because the creation query does not finish in time.
If I pass ...
0
votes
1
answer
50
views
How to atomically replace a file?
I'm currently using:
if Path::new(&filename).exists() {
remove_file(&filename)?;
debug!("old output file deleted: {filename}");
}
let mut file = OpenOptions::new()
....
0
votes
1
answer
68
views
Avoid or mitigate race condition for two functions sharing same variable (resource) in C#
I have two functions in different classes, and they are generating race condition.
One function is updating variables value and another one is using variable, and they are in Race condition my ...
0
votes
1
answer
73
views
Deadlock when waiting from multiple threads on same std::condition_variable_any::wait_for with std::stop_token
In an application I'm writing I have a threading model which is a simplified as the following:
a generator jthread (m_WorkerGenerator) is starting async tasks.
the multiple async tasks work until the ...
1
vote
1
answer
59
views
Handling race condition in Firebase messaging service
I'm using the following code to display chat notifications in my android app.
//copy old notification (if any)
Notification oldNotification = getActiveNotification(...
1
vote
2
answers
39
views
Race condition from long running task firing update events
My goal is to implement a concurrent method using event based asynchronous programming (EBAP) model, to handle status changes on a viewmodel. I have a long running task that is queued from the UI ...
0
votes
1
answer
35
views
Eliminate duplicate urls (Web scraping RACE condition)
I am trying to scarpe a website with 2 years, 2015and 2022. I am trying to retrieve all pdf from below update. In each year we have many pdf Urls I am trying to insert data in {year: pdf_link} format....
0
votes
1
answer
74
views
Race condition on std::jthread when getting the std::stop_token internally
Following the question from here, which explains to some degree why getting a std::stop_token internally instead of getting it as parameter to the thread wrapper function leads to a race-condition. I ...
1
vote
0
answers
57
views
Angular router useFactory function not always called
In Angular 15, I have created an Angular Routing module that builds a list of routes dynamically according to the code below. For whatever reason, the useFactory specified provider function is only ...
-1
votes
1
answer
73
views
Problem with outer loop vectorization using OpenMP in C
I am lerning how to use OpenMP to make a code use muttiple processors. Recently, I tried to make my Ewald Summation Fourier part parallel using OpenMP. Below is the function named ...
1
vote
1
answer
39
views
MongoDB "atomic" find entity and if not found update a different one
I am trying to solve a race condition issue through MongoDB operations so I can avoid the implementation of locks.
My goal is to be able to check if there is any document with a certain status in the ...
0
votes
1
answer
23
views
How is racecondition possible between the process?
I understand that race condition is possible between threads because they are operating on the same Data.
So in my CS course I learned that the main difference between process and thread is that ...
0
votes
1
answer
65
views
Is Thread Sanitizer expected to be able to correctly analyze lock-free code?
Background motivation: I have some code that uses a lock-free algorithm to share audio data to/from a CoreAudio callback (only because CoreAudio callbacks-threads are real-time and therefore aren't ...
1
vote
1
answer
32
views
Parallel fetches capture the component state leading to race condition
Description
What I Need
I want to trigger several fetch-based Promises in parallel. Whenever each of these promises resolves, the value should be processed and appended to component state (items). In ...
0
votes
0
answers
24
views
If I private-`mmap` a file and read it, then another process writes to the same file, will another read at the same location return the same value?
(Context: I'm trying to establish which sequences of mmap operations are safe from the "memory safety" point of view, i.e. what assumptions I can make about mmaped memory without risking ...
0
votes
0
answers
6
views
I have one json column in postgres which contains an Java map. How can we prevent race condition on json db map when i have multiple server?
I have one json column in postgres which contains an Java map. How can we prevent race condition on json db map when i have multiple server?
If we put synchronize method it also won't work because we ...
1
vote
2
answers
120
views
Unexpected output of multithreaded C++ program
I'm studying concurrency in C++ and I'm trying to implement a multithreaded callback registration system. I came up with the following code, which is supposed to accept registration requests until an ...
0
votes
2
answers
67
views
Why is There a Deadlock Occurring Randomly in a Producer/Consumer Multithreaded C++ Program?
In the code shown below, we were tasked with creating a consumer/producer program using multithreading and to find a way to prevent deadlock. This is my code:
#include <iostream>
#include <...
0
votes
1
answer
62
views
One more releasing and acquiring locks make performance worse unexpectedly
My program has 8 writing threads and one persistence thread. The following code is the core of the persistence thread
std::string longLine;
myMutex.lock();
while (!myQueue.empty()) {
...
0
votes
1
answer
63
views
Does shared_ptr guarantee thread safety for the underlying object?
Problem
I believe the following code should lead to runtime issues, but it doesn't. I'm trying to update the underlying object pointed to by the shared_ptr in one thread, and access it in another ...
1
vote
0
answers
59
views
INCONSISTENCY - Effect callbacks are synchronous to prevent race conditions - Does useEffect run asynchronous or synchronous?
Does a render happen before function in React Hooks useEffect is called?
useLayoutEffect which is executed synchronously after all DOM
mutations. Use this to read layout from the DOM and ...
0
votes
1
answer
69
views
Race condition in tbb::concurrent_queue
I am having a data race problem on tbb::concurrent_queue. Here is the code, producer and consumer functions are running on separate threads:
tbb::concurrent_queue<std::string> valid_json_queue;
...
0
votes
1
answer
45
views
Trying to implement a cleanup in a useEffect to prevent no-op memory leak error
I am trying to update a piece of UI based on a conditional. The conditional is set by a database call in a separate component. It sometimes works, but often doesn't. When it doesn't work, it gets this ...
0
votes
0
answers
34
views
Race condition in React app rendered in iframe in Cypress
I have a Cypress test that is testing a dialog located rendered as a sibling of the iframe. The opening of that dialog is triggered from outside of the iframe, the problem is that I need to check for ...
5
votes
1
answer
87
views
Using the readlink function to avoid symbolic link race conditions when opening a file path
I'm reading this paper. On the page 11 the paper says:
Unix applications can obtain access to files without encountering symlink races. This is important for normal application programmers who, for ...
0
votes
1
answer
68
views
Oracle Concurrency Problem with competing race condition
I am facing a concurrency problem with Oracle DB. Say I have 3 Objects of type A that need to be processed and only on the final processing of an Object A can I move on to processing Objects of type B....
0
votes
1
answer
68
views
How to prevent race condition or reduce its possibility
I'm trying to reduce the possibility of a race condition if invalidation of my redis cache occurs at the same time I'm retrieving from the cache. Note that invalidation and retrieval happen on two ...
0
votes
0
answers
11
views
Can pidfd prevent pid cycling
I am thinking of implementing a sandbox using seccomp + unotify mechanism and I am stuck thinking about how to intercept syscall pidfd_open safely.
I want to intercept the syscall so that pidfd_open ...
0
votes
0
answers
62
views
inotifywait: new event triggered while processing the older one
I have the following loop:
while inotifywait -qq --event close_write "$filebs" "$filevp"; do
do_something()
done
The problem is that, at certain times, two events are ...
0
votes
0
answers
59
views
Fortify race condition format flaw issue Date Formatting [duplicate]
Hello i am working on a code and i get Fortify Race Condition:Format Flaw issue and i don't know how to fix it. I have searched on stackoverflow and i couldn't find an accurate way to fix it.
I get ...
0
votes
0
answers
23
views
Race condition in multiple instance in kubernates
Hi i have a race condition in given method i have 2 instances in kubernates and checking in redis
public void method(GuestDTO guestDTO) {
String executeName = "addingGuestToCache" + ...
1
vote
0
answers
46
views
Why is this Binary Tree return true instead of false?
My goal is to use Binary Tree for Operation Room Booking. The problem is the return false, nil magically become return true, nil. I am not sure if this is a race condition or not. But I am confused.
...
0
votes
1
answer
61
views
golang race with channels and return in a function
I have the following 3 files:
go.mod
module example
go 1.19
main.go
package main
import "fmt"
func number(out chan int) bool {
defer close(out)
for i := 0; i < 5; i++ {
...
1
vote
0
answers
29
views
Multiple API calls competing for one atomic db action
I have an API to send message and create contact as such: when it is called and detected no such contact in the database, it first creates a contact, then send out the message.
The problem is: when ...
1
vote
2
answers
43
views
PostgreSQL trigger race condition updating a balance table from transactions
I have a financial system where users have tokens and can add transactions. The system has to calculate the balance and mean acquisition price of each token. Data integrity is of utmost importance in ...
0
votes
0
answers
78
views
Race condition in Google Appsheet when updating row after created
It seems I'm experiencing a race condition in Google Appsheet:
I've configured a Behavior in my form view: Once the form is saved -> run 'Data: set the values of some columns in this row' (edit one ...
1
vote
0
answers
66
views
Is it advisable to use locks in multithreaded real-time code when they are contained within a class?
In the situation where you have a high priority real-time data processing thread reading from a parameter and a second thread with lower priority writing to the parameter (or vice versa) you can end ...
0
votes
0
answers
51
views
Google Cloud Run - One container handling multiple similar requests with queue for each user
I have a SERVICE that gets a request from a Webhook and this is currently deployed across seperate Cloud Run containers. These seperate containers are the exact same (image), however, each instance ...
0
votes
0
answers
41
views
What is a reliable method to distinguish between different clones during collisions in Scratch?
I'm working on a game, in which I have a spell system. Different spells deal different amounts of damage to enemies. I need a way for either the enemies, or the spells, to distinguish with which ...
0
votes
0
answers
54
views
How can I avoid the following race condition using condition variables?
I have a recipe of several steps where each steps may or may not control a motor. For this, I created a thread that sends a command to the motor. I used to join that thread, as each steps needed to ...
-1
votes
2
answers
53
views
Does Swift task run first or print() first when I tap my UIButton?
I am trying to understand what is going on in my code here.
I have a simple API call to open weahter API and that whenever the user taps the UIButton, it should call the api and get the data back from ...
0
votes
1
answer
43
views
React race condition causing undefined id
I am just trying to figure out a weird issue in my React project. So I am executing some code in my useEffect. As you can see, I am trying to grab the currentObj from an array of objects based on ...