Skip to content

[Tranga broke]: Running the same search term twice causes internal server error. #535

@clovisNyu

Description

@clovisNyu

What is broken?

On the /v2/Search/{MangaConnectorName}/{Query}, if I use the same query twice, the second call will return a 500 Internal Server Error. I also tried running /v2/Maintenance/CleanupNoDownloadManga, but the problem doesn't go away. The logs seem to indicate a conflicting entry in the database.

Log-output

tranga-api  | 2025-12-28 23:20:55,393 [82] DEBUG API.Tranga - Adding Manga to Context: Manga-b897bad184f820ceb5a8d93c09084547 Bocchi the Rock!
tranga-api  | 2025-12-28 23:20:56,987 [88] DEBUG API.Tranga - Merging with existing Manga: Manga-b897bad184f820ceb5a8d93c09084547 Bocchi the Rock!
tranga-api  | fail: Microsoft.AspNetCore.Server.Kestrel[13]
tranga-api  |       Connection id "0HNI5533EGLF5", Request id "0HNI5533EGLF5:00000005": An unhandled exception was thrown by the application.
tranga-api  |       System.AggregateException: One or more errors occurred. (The instance of entity type 'MangaConnectorId<Manga>' cannot be tracked because another instance with the same key value for {'Key'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values.)
tranga-api  |        ---> System.InvalidOperationException: The instance of entity type 'MangaConnectorId<Manga>' cannot be tracked because another instance with the same key value for {'Key'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values.
tranga-api  |          at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap`1.ThrowIdentityConflict(InternalEntityEntry entry)
tranga-api  |          at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap`1.Add(TKey key, InternalEntityEntry entry, Boolean updateDuplicate)
tranga-api  |          at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.StartTracking(InternalEntityEntry entry)
tranga-api  |          at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState oldState, EntityState newState, Boolean acceptChanges, Boolean modifyProperties)
tranga-api  |          at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.PaintAction(EntityEntryGraphNode`1 node)
tranga-api  |          at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph[TState](EntityEntryGraphNode`1 node, Func`2 handleNode)
tranga-api  |          at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.AttachGraph(InternalEntityEntry rootEntry, EntityState targetState, EntityState storeGeneratedWithKeySetTargetState, Boolean forceStateWhenUnknownKey)
tranga-api  |          at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.NavigationCollectionChanged(InternalEntityEntry entry, INavigationBase navigationBase, IEnumerable`1 added, IEnumerable`1 removed)
tranga-api  |          at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectNavigationChange(InternalEntityEntry entry, INavigationBase navigationBase)
tranga-api  |          at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.LocalDetectChanges(InternalEntityEntry entry)
tranga-api  |          at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(IStateManager stateManager)
tranga-api  |          at Microsoft.EntityFrameworkCore.ChangeTracking.ChangeTracker.Entries()
tranga-api  |          at API.Schema.TrangaBaseContext`1.Sync(CancellationToken token, Type trigger, String reason)
tranga-api  |          at API.Tranga.AddMangaToContext(MangaContext context, Manga addManga, MangaConnectorId`1 addMcId, CancellationToken token) in /src/API/Tranga.cs:line 237
tranga-api  |          at API.Tranga.AddMangaToContext(MangaContext context, ValueTuple`2 addManga, CancellationToken token) in /src/API/Tranga.cs:line 199
tranga-api  |          --- End of inner exception stack trace ---
tranga-api  |          at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
tranga-api  |          at System.Linq.Enumerable.CastIterator[TResult](IEnumerable source)+MoveNext()
tranga-api  |          at System.Linq.Enumerable.IEnumerableSelectIterator`2.ToList()
tranga-api  |          at API.Controllers.SearchController.SearchManga(String MangaConnectorName, String Query) in /src/API/Controllers/SearchController.cs:line 51
tranga-api  |          at lambda_method806(Closure, Object, Object[])
tranga-api  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
tranga-api  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
tranga-api  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
tranga-api  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
tranga-api  |       --- End of stack trace from previous location ---
tranga-api  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
tranga-api  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
tranga-api  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
tranga-api  |       --- End of stack trace from previous location ---
tranga-api  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
tranga-api  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
tranga-api  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
tranga-api  |          at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
tranga-api  |          at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
tranga-api  |          at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
tranga-api  |          at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
tranga-api  |          at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
tranga-api  | 2025-12-28 23:20:58,923 [64] DEBUG API.Tranga - Starting StartNewChapterDownloadsWorker-uiap5i2v08shwrax4pkkeqa5m2qhwfmlm
tranga-api  | 2025-12-28 23:20:58,923 [64] DEBUG API.Workers.PeriodicWorkers.StartNewChapterDownloadsWorker - Checking StartNewChapterDownloadsWorker-uiap5i2v08shwrax4pkkeqa5m2qhwfmlm
tranga-api  | 2025-12-28 23:20:58,923 [64] INFO  API.Workers.PeriodicWorkers.StartNewChapterDownloadsWorker - Running StartNewChapterDownloadsWorker-uiap5i2v08shwrax4pkkeqa5m2qhwfmlm
tranga-api  | 2025-12-28 23:20:58,923 [64] DEBUG API.Workers.PeriodicWorkers.StartNewChapterDownloadsWorker - Checking for missing chapters...
tranga-api  | 2025-12-28 23:20:58,925 [64] DEBUG API.Workers.PeriodicWorkers.StartNewChapterDownloadsWorker - Found 0 missing chapters.
tranga-api  | 2025-12-28 23:20:58,925 [64] DEBUG API.Workers.PeriodicWorkers.StartNewChapterDownloadsWorker - 0 chapter not being downloaded
tranga-api  | 2025-12-28 23:20:58,925 [64] DEBUG API.Workers.PeriodicWorkers.StartNewChapterDownloadsWorker - 0 running download Workers. 9 available new download Workers.
tranga-api  | 2025-12-28 23:20:58,925 [64] INFO  API.Workers.PeriodicWorkers.StartNewChapterDownloadsWorker - Completed StartNewChapterDownloadsWorker-uiap5i2v08shwrax4pkkeqa5m2qhwfmlm
tranga-api  |   1.4159 ms
tranga-api  | 2025-12-28 23:20:58,925 [64] DEBUG API.Tranga - DefaultAfterWork StartNewChapterDownloadsWorker-uiap5i2v08shwrax4pkkeqa5m2qhwfmlm
tranga-api  | 2025-12-28 23:20:58,925 [64] DEBUG API.Tranga - Children done StartNewChapterDownloadsWorker-uiap5i2v08shwrax4pkkeqa5m2qhwfmlm
tranga-api  | 2025-12-28 23:20:58,925 [64] DEBUG API.Tranga - StartNewChapterDownloadsWorker-uiap5i2v08shwrax4pkkeqa5m2qhwfmlm created 0 new Workers.
tranga-api  | 2025-12-28 23:20:58,925 [64] DEBUG API.Tranga - Refreshing StartNewChapterDownloadsWorker-uiap5i2v08shwrax4pkkeqa5m2qhwfmlm
tranga-api  | 2025-12-28 23:20:58,925 [64] DEBUG API.Tranga - Waiting 00:01:00 for next run of StartNewChapterDownloadsWorker-uiap5i2v08shwrax4pkkeqa5m2qhwfmlm

Tranga version

tranga-api  | 2025-12-27 09:17:27,547 [1] INFO  Startup -
tranga-api  |
tranga-api  |  _______                                 v2
tranga-api  | |_     _|.----..---.-..-----..-----..---.-.
tranga-api  |   |   |  |   _||  _  ||     ||  _  ||  _  |
tranga-api  |   |___|  |__|  |___._||__|__||___  ||___._|
tranga-api  |                              |_____|
tranga-api  | --11/25/2025 21:07:51 for AnyCpu

Additional stuff

No response

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions