C
C#2w ago
bdcp

✅ Can this produce an DeadLock?

Im not sure in combination with linq an dead lock can occur. But this runs in an Azure Function, and it just stopped working. No crashes, it timeout after 6 hours. No further logs
No description
49 Replies
SleepWellPupper
Looks fine to me. Did you try to recreate the conditions before the timeout?
SleepWellPupper
this article outlines some practices for implementing logging that helps you recreate program state after the fact. Maybe it can help you if this issue reoccurs.
Repeatable execution
What to log, and how to log it.
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
SleepWellPupper
Where?
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
SleepWellPupper
no It returns Task<T> it's a select, it cannot be void
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
SleepWellPupper
No, it's a Select<TInput, Task<TOutput>>(Func<TInput, Task<TOutput>> selector)
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
SleepWellPupper
There is no async void here. It returns a Task<StockInfoResponse[]>
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
bdcp
bdcpOP2w ago
Sleep is right, it's not an async void
No description
bdcp
bdcpOP2w ago
that's also the behaviour i want, if a request fails, the rest can crash and burn, there a polly retry in there
SleepWellPupper
Yeah, I don't really see how this can silently fail.
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
SleepWellPupper
Have you read the OP?
bdcp
bdcpOP2w ago
Parallel.ForEachAsync isnt a thing either on functions right?
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
bdcp
bdcpOP2w ago
i mean functions is not nice with threads
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
bdcp
bdcpOP2w ago
just a isolated worker, not durable?
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
bdcp
bdcpOP2w ago
it stops logging traces all together to app insights maybe verbocity is a good idea but g2g ill look later again
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
canton7
canton72w ago
Why on earth wouldn't you do that? Severe skill issue here 🙂 The consumer of a method doesn't care whether it's async or not. Only whether it returns a Task or not. It doesn't matter whether that Task is being returned from another method, or created by the async machinery
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
bdcp
bdcpOP2w ago
Nope its not durable, was just making sure we were talking about the same thing
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
bdcp
bdcpOP2w ago
i was able to reproduce it locally, with adding logs everywhere i was able to narrow it down to a line a code. Honestly i can't explain the error. But the main issue is Azure Function seem to throw an error silently, and doesnt kill the app it just hangs
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
bdcp
bdcpOP2w ago
it is indeed unrelated to the code i gave above
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
bdcp
bdcpOP2w ago
so the code above gathers stock info of products right, then we use that stock info to remove products of a favorite lists. It might be hard to believe but the error happend on line 21, when i added logs everywhere around that code that's where it got stuck. Now in DeleteitemRequest i added .ToList() to favorites before creating it and that solved the issue. I never got an error thrown or stacktrace. It doesnt happen in my testcontainers. favoriteRepository is a cosmos db
No description
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
bdcp
bdcpOP2w ago
it never reached line 26, so it never reached cosmos
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
bdcp
bdcpOP2w ago
public record DeleteItemsRequest(
Guid? FavoriteListId,
CustomerMasterId CustomerMasterId,
IEnumerable<RemoveFavoriteItem> Favorites
);

// The Caller:

var articlesToDelete = orderedFavorites
.Skip(_maxProductsPerList)
.Select(o => new RemoveFavoriteItem(o.ArticleNumber));

var deleteItemsRequest = new DeleteItemsRequest(
favoList.Id,
new CustomerMasterId(favoList.CustomerMasterId),
articlesToDelete.ToList() // <-- fix is here
);
public record DeleteItemsRequest(
Guid? FavoriteListId,
CustomerMasterId CustomerMasterId,
IEnumerable<RemoveFavoriteItem> Favorites
);

// The Caller:

var articlesToDelete = orderedFavorites
.Skip(_maxProductsPerList)
.Select(o => new RemoveFavoriteItem(o.ArticleNumber));

var deleteItemsRequest = new DeleteItemsRequest(
favoList.Id,
new CustomerMasterId(favoList.CustomerMasterId),
articlesToDelete.ToList() // <-- fix is here
);
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
bdcp
bdcpOP2w ago
yes
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
bdcp
bdcpOP2w ago
var orderedFavorites = favoList
.Favorites.Select(f =>
{
var stock = stockInfo.SingleOrDefault(s => s.ArticleNumber == f.ArticleNumber);

var canBeIndexed = stock?.CanBeIndexed ?? false; // false if not found
var lastUnlistedAt = stock?.LastUnlistedAt;

return new
{
f.ArticleNumber,
CanBeIndexed = canBeIndexed,
f.DateTimeCreated,
LastUnlistedAt = lastUnlistedAt,
};
})
.OrderByDescending(o => o.CanBeIndexed)
.ThenByDescending(o => o.CanBeIndexed ? o.DateTimeCreated : o.LastUnlistedAt);
var orderedFavorites = favoList
.Favorites.Select(f =>
{
var stock = stockInfo.SingleOrDefault(s => s.ArticleNumber == f.ArticleNumber);

var canBeIndexed = stock?.CanBeIndexed ?? false; // false if not found
var lastUnlistedAt = stock?.LastUnlistedAt;

return new
{
f.ArticleNumber,
CanBeIndexed = canBeIndexed,
f.DateTimeCreated,
LastUnlistedAt = lastUnlistedAt,
};
})
.OrderByDescending(o => o.CanBeIndexed)
.ThenByDescending(o => o.CanBeIndexed ? o.DateTimeCreated : o.LastUnlistedAt);
Favolist is an object directly from cosmos
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
bdcp
bdcpOP2w ago
there's a toList earlier in the call too but only for ids
No description
bdcp
bdcpOP2w ago
yea but still the issue is it's throwing something and the function doesnt bubble it up
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
bdcp
bdcpOP2w ago
This is the issue. There isnt one, it just breaks and hangs. I'd like to see the error too I only found the line due to adding logs everywhere, so now your guess is as good as mine
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
bdcp
bdcpOP2w ago
im still puzzled that i ran into this and there's not github issue for it. I can't be the first with a silent crash?
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?