You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@answer.apache.org by "AsyncAssassin (via GitHub)" <gi...@apache.org> on 2026/06/17 08:26:01 UTC
[PR] feat(notification): add interval for new question emails [answer]
AsyncAssassin opened a new pull request, #1545:
URL: https://github.com/apache/answer/pull/1545
## Summary
Adds a configurable interval between email send attempts for new-question / followed-tag notification fan-out.
The interval is controlled by `NEW_QUESTION_NOTIFICATION_EMAIL_SEND_INTERVAL_SECONDS`.
The default is `0`, so the current behavior is preserved unless the environment variable is explicitly set. Empty, invalid, negative, or overflowing values also fall back to `0`.
## Scope
This is based on the scope discussed in #625 and confirmed by @LinkinStars.
This PR only applies the delay to new-question notification email fan-out. It does not change:
- daily digest behavior
- logged-in user handling
- verification emails
- password reset emails
- SMTP test emails
- the shared `EmailService.Send`
- UI/admin settings
- migrations
When the interval is enabled, plugin notifications are sent before the throttled email fan-out, so they are not delayed by the configured sleep.
## Tests
Added focused tests for:
- environment variable parsing
- delay ordering between email attempts
- disabled/non-email channel handling
- unsubscribe token generation per email attempt
- service-level new-question fan-out behavior with fake service dependencies
Validation:
```bash
go test -count=1 ./internal/service/notification/...
go test -race -count=1 ./internal/service/notification/...
go test -count=1 ./internal/...
go test -count=1 ./...
go vet ./internal/service/notification/...
git diff --check
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@answer.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@answer.apache.org
For additional commands, e-mail: issues-help@answer.apache.org
Re: [PR] feat(notification): add interval for new question emails [answer]
Posted by "AsyncAssassin (via GitHub)" <gi...@apache.org>.
AsyncAssassin commented on PR #1545:
URL: https://github.com/apache/answer/pull/1545#issuecomment-4820850771
Thanks for the review. I pushed a follow-up commit that moves the throttled new-question email fan-out out of `handleNewQuestionNotification` and into a dedicated serial `new_question_email` worker.
The handler now collects subscribers, syncs plugin notifications, enqueues the email task, and returns without sleeping or sending throttled SMTP inline. The worker uses a bounded queue, context-aware timer/select waits, and clamps the configured interval to a 5-minute maximum. Unrelated external notifications should no longer be delayed by new-question email throttling.
I also added coverage for the worker timing/cancellation behavior, enqueue/close race, full/closed queue cases, handler enqueue behavior, plugin-before-enqueue ordering, and interval parsing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@answer.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@answer.apache.org
For additional commands, e-mail: issues-help@answer.apache.org
Re: [PR] feat(notification): add interval for new question emails [answer]
Posted by "LinkinStars (via GitHub)" <gi...@apache.org>.
LinkinStars merged PR #1545:
URL: https://github.com/apache/answer/pull/1545
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@answer.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@answer.apache.org
For additional commands, e-mail: issues-help@answer.apache.org
Re: [PR] feat(notification): add interval for new question emails [answer]
Posted by "LinkinStars (via GitHub)" <gi...@apache.org>.
LinkinStars commented on PR #1545:
URL: https://github.com/apache/answer/pull/1545#issuecomment-4778327185
Thanks for working on this. The scope matches the discussion in #625, and the default `0` interval preserves the current behavior.
One concern: the current implementation sleeps inside `handleNewQuestionNotification`. Since `external_notification` is processed by a single queue worker, this does not only throttle new-question emails. A large fan-out with a configured interval can block the whole external notification queue, delaying unrelated notifications such as new answer, new comment, and invite-answer emails.
There is also a shutdown concern because the wait uses `time.Sleep`, so it cannot be cancelled. If the interval is large or misconfigured, queue shutdown may have to wait for the sleep to finish.
I think a better approach would be to move the throttled new-question email fan-out into a dedicated queue/worker:
- `handleNewQuestionNotification` collects subscribers, syncs plugin notifications, enqueues new-question email tasks, and returns immediately.
- A dedicated `new_question_email` worker consumes those tasks serially.
- The worker waits between email attempts using a context-aware timer/select instead of bare `time.Sleep`.
- The interval should probably have a reasonable upper bound to avoid accidental long blocking from misconfiguration.
This would keep the intended email throttling behavior while avoiding delays for unrelated external notifications and making shutdown behavior safer.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@answer.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@answer.apache.org
For additional commands, e-mail: issues-help@answer.apache.org
Re: [PR] feat(notification): add interval for new question emails [answer]
Posted by "AsyncAssassin (via GitHub)" <gi...@apache.org>.
AsyncAssassin commented on PR #1545:
URL: https://github.com/apache/answer/pull/1545#issuecomment-4852910653
Thanks, I pushed a small follow-up commit for the worker queue size.
The `new_question_email` worker now defaults to a queue size of `1024` and can be configured with `NEW_QUESTION_NOTIFICATION_EMAIL_QUEUE_SIZE`. Invalid, empty, zero, negative, and overflow values fall back to `1024`, and very large values are clamped to `65536`.
I also added focused tests for the parser and constructor capacity.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@answer.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@answer.apache.org
For additional commands, e-mail: issues-help@answer.apache.org
Re: [PR] feat(notification): add interval for new question emails [answer]
Posted by "LinkinStars (via GitHub)" <gi...@apache.org>.
LinkinStars commented on PR #1545:
URL: https://github.com/apache/answer/pull/1545#issuecomment-4849974353
Thanks for the follow-up update. The new dedicated worker design addresses the main concern about blocking unrelated external notifications, and the context-aware wait plus interval cap look good. I think this is very close now; there is just one remaining concern about the worker queue size.
Right now `newQuestionEmailWorkerQueueSize` is fixed at `128`, and when the queue is full, `TryEnqueue` drops the whole new-question email task. For sites with many followed tags/subscribers, SMTP sending can be much slower than new-question creation, so this queue may fill up quickly and later notification emails would be skipped.
Could we change the default queue size from `128` to `1024`, and also make it configurable by environment variable? For example:
- default: `1024`
- env var: `NEW_QUESTION_NOTIFICATION_EMAIL_QUEUE_SIZE`
- invalid, empty, zero, or negative values fall back to `1024`
- optionally clamp extremely large values to a reasonable maximum
This should cover most installations by default, while still allowing larger sites to tune the backlog capacity based on their user count and SMTP throughput.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@answer.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@answer.apache.org
For additional commands, e-mail: issues-help@answer.apache.org