Slow "On Series Add" notification delays the search for missing episodes after add
Is there an existing issue for this?
- I have searched the existing open and closed issues
Current Behavior
When you add a series with addOptions.searchForMissingEpisodes: true, Sonarr does not queue the search until every "On Series Add" notification returns. This applies to POST /api/v3/series and to "Start search for missing episodes" in the UI. If one notification hangs, the search waits for the full HTTP timeout of about 100 s.
SeriesScannedHandler.HandleScanEvents publishes SeriesAddCompletedEvent before it pushes MissingEpisodeSearchCommand. NotificationService handles that event on the same thread, so the push waits for all notifications.
Expected Behavior
Sonarr queues the search immediately after the add. A slow notification does not delay the search.
Steps To Reproduce
- Add a Webhook connection with "On Series Add" enabled. Point it at a server that does not respond to the
SeriesAddevent. - Send
POST /api/v3/serieswithaddOptions.searchForMissingEpisodes: true. - In
GET /api/v3/command, compare thequeuedtime ofMissingEpisodeSearchwith the time of the add.
Results on v5-develop (a8a8290, built from source):
| Webhook | Series added | MissingEpisodeSearch queued |
|---|---|---|
| Hangs | 19:45:54 | 19:47:35 (+101 s) |
| Disabled | 19:47:46 | 19:47:46 |
| Hangs, with the change below | 19:48:24 | 19:48:25 |
Environment
- OS: Fedora 44 host (k3s), Alpine 3.24.1 container
- Sonarr: 4.0.20.3012
- Docker Install: Yes (linuxserver.io 4.0.20.3012-ls191)
- Using Reverse Proxy: Yes (Traefik)
- Browser: n/a
- Database: SQLite 3.53.4
What branch are you running?
Develop
Trace Logs
[Info] SeriesScannedHandler: [American Horror Story] was recently added, performing post-add actions
[Warn] NotificationService: Unable to send OnSeriesAdd notification to: <webhook>
System.Net.WebException: Http request timed out
[Info] EpisodeSearchService: Performing search for 3 episodesAnything else?
Only NotificationService handles SeriesAddCompletedEvent, and no notification reads AddOptions. So HandleScanEvents can publish the event last:
--- a/src/NzbDrone.Core/Tv/SeriesScannedHandler.cs
+++ b/src/NzbDrone.Core/Tv/SeriesScannedHandler.cs
@@ -46,8 +46,6 @@ private void HandleScanEvents(Series series)
_logger.Info("[{0}] was recently added, performing post-add actions", series.Title);
_episodeMonitoredService.SetEpisodeMonitoredStatus(series, addOptions);
- _eventAggregator.PublishEvent(new SeriesAddCompletedEvent(series));
-
// If both options are enabled search for the whole series, which will only include monitored episodes.
@@ -71,6 +69,8 @@ private void HandleScanEvents(Series series)
series.AddOptions = null;
_seriesService.RemoveAddOptions(series);
+
+ _eventAggregator.PublishEvent(new SeriesAddCompletedEvent(series));
}Radarr's MovieScannedHandler already pushes the search first.
Source: Sonarr/Sonarr