For the past couple of days I've been struggling with a really strange issue. I have a .net-core 2.1 console app that has been thoroughly tested on Windows 10 and works perfectly there. However, when deploying it for Ubuntu 18.04 and running it there, the app starts behaving strangely. I deploy it like so:
dotnet publish .\MyProject.csproj -c Release -r ubuntu.18.04-x64 --output ./published
What the console app does essentially, is run a function every second, which runs multiple threads using the ThreadPool class (up to 4). Each of those threads from the threadpool do some calculations and write the results in a database. The threads are independent from each other, don't communicate, don't wait for others to finish, and use separate instances of the same class to do the calculations and db writing. This is how the threads are invoked each second:
foreach (var item in items)
{
ThreadPool.QueueUserWorkItem(obj =>
{
DoTheCalcAndWriteToDb();
});
}
The expected output, which works on Windows, is each of the threads printing their results to the console and printing the second for which the function was run for. Here is the log example for second 45 and 46:
Thread 1 info: Function done in second: 45:464
Thread 2 info: Function done in second: 45:464
Thread 3 info: Function done in second: 45:484
Thread 4 info: Function done in second: 45:504
---
Thread 1 info: Function done in second: 46:445
Thread 2 info: Function done in second: 46:445
Thread 3 info: Function done in second: 46:454
Thread 4 info: Function done in second: 46:485
As you can see, each thread is invoked at each second through the ThreadPool, and finished at the same second.
Now the behavior on Linux (Ubuntu) is completely different. Running it for a few seconds gives the same results and seems to work as same as on Windows, but after a few minutes (never the same time) the logs become inconsistent. Some print after a few seconds, and others don't print at all. After the problems start they never return to the regular state. Of course, it's not just the printing, the db also doesn't have new data inserted in it every second (it should have 4 new fields in it, every second).
I'm sorry for the limited information, but I currently can't determine where the problem is or what other info to give you in order to figure out what is causing the issue.
Does anyone have any idea where the problem might be? I can provide more info regarding the calculations and the db work, but it's really nothing special just some math and then write that to a new field in RethinkDB.