fix(email-connectors): add 10s HTTP timeouts to all adapters and offload bulkExportContacts to background jobs
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- postgresql, react, typescript
Research direction
Start with the five adapters under packages/email-connectors/src/adapters/, the DTO and service named in the issue, and the worker job handler at apps/workers/src/services/db-job-poller.ts. Trace the existing export request through the controller and frontend before estimating the queue and status changes. Done means adapter timeouts, contact validation, background processing with progress and completion counts, and a non-blocking export status flow are covered.
Written by the indexing model from the issue text.
Description
Problem Description
-
No HTTP timeouts in any of the 5 Email Connector adapters:
Inpackages/email-connectors/src/adapters/*.adapter.ts(KlaviyoAdapter,MailchimpAdapter,KitAdapter,FlodeskAdapter,ActiveCampaignAdapter), none of thefetch()calls pass anAbortControllertimeout. If an ESP stalls,dispatchDualWrite,retryFailedSyncs, andbulkExportContactshang until the OS TCP timeout (2-5 minutes), tying up API concurrency. -
Synchronous unbounded
bulkExportContactstimes out at scale:
Inapps/api/src/email-connectors/email-connectors.service.ts(bulkExportContacts, lines 541-612),POST /email-connectors/bulk-exportpushes all contacts synchronously inside the HTTP request lifecycle, andBulkExportContactsDto(apps/api/src/email-connectors/dto/email-connectors.dto.ts, lines 86-107) lacks@IsArray(),@ArrayMaxSize(), and@ValidateNested()validation.
For 1,000–30,000+ contacts, the HTTP request exceeds reverse-proxy/gateway timeouts (30-60s504), hits ESP rate limits (429), and forces the user to stay blocked on the page.
Expected Behavior
- Every
fetch()call in all 5 email adapters enforces a 10-secondAbortControllertimeout (always clearing the timer infinally) and returns a clear retryable error on timeout ("Provider timed out after 10s, please retry"). BulkExportContactsDto.contactsis validated (@IsArray(),@ArrayMaxSize(10000),@ValidateNested({ each: true })).- Large bulk exports run asynchronously in the background without blocking the user's browser or starving real-time DM/comment worker queues.
- The user can navigate anywhere immediately after clicking Export, see a non-blocking progress/status indicator, and receive a completion notification with final
synced/failedcounts.
Where to Look
packages/email-connectors/src/adapters/*.adapter.ts(klaviyo,mailchimp,kit,flodesk,activecampaign)apps/api/src/email-connectors/dto/email-connectors.dto.ts(BulkExportContactsDto)apps/api/src/email-connectors/email-connectors.service.ts(bulkExportContacts,dispatchDualWrite,retryFailedSyncs)apps/api/src/email-connectors/email-connectors.controller.tsapps/workers/src/services/db-job-poller.ts(worker job handler)apps/web(bulk export trigger & status toast/notification)
Solution / Implementation Guide (Zero-Breakage Plan)
-
10s Timeout Helper Across All 5 Email Adapters (
packages/email-connectors):- Add a shared
fetchWithTimeout(url, init, timeoutMs = 10000)helper usingAbortController+try { ... } finally { clearTimeout(timer); }. - Catch
AbortErrorcleanly and return{ success: false, error: 'Request timed out after 10s. Please retry.' }so existing callers (dispatchDualWrite,testConnection,getAudiences) never crash on unhandled rejections.
- Add a shared
-
DTO Validation (
email-connectors.dto.ts):- Add
@IsArray(),@ArrayMaxSize(10000),@ValidateNested({ each: true }), and@Type(() => BulkExportContactItemDto)onBulkExportContactsDto.contacts.
- Add
-
Background Job Queueing Without Starving DM Workers (
apps/api+apps/workers):- Enqueue
jobType: 'BULK_EMAIL_EXPORT'inBackgroundJobwith low priority (priority: 10) so real-time InstagramSEND_DM/ comment jobs (priority: 1) always run first. - Store only
{ companyId, userId, connectorId, listId, contacts }in the job payload — never store decrypted API keys inBackgroundJob.payload(the worker decrypts connector credentials at execution time). - Process contacts in small rate-limit-safe batches (e.g., 5-10 concurrent with brief pacing and
429backoff), batch-insertEmailConnectorSyncLogrows viacreateManyper chunk, and update job progress ({ processed, total, synced, failed }) soGET /email-connectors/bulk-export/:jobIdcan report progress. - When finished, create a
NotificationforuserId/companyId("Bulk email export complete: X synced, Y failed"). - Backward compatibility: If
contacts.length <= 50,bulkExportContactscan optionally still execute inline and return{ synced, failed, errors }immediately, or the controller + frontend can handle{ jobId, status: 'QUEUED' }consistently in the same PR.
- Enqueue
-
Non-Blocking Frontend UX (
apps/web):- On export submit, show a non-blocking toast / subtle background badge ("Exporting contacts in background..."), allow the user to navigate freely, and poll
GET /email-connectors/bulk-export/:jobId(or listen for notifications) to surface the final completion toast.
- On export submit, show a non-blocking toast / subtle background badge ("Exporting contacts in background..."), allow the user to navigate freely, and poll
- Dominant language
- TypeScript
- Stars
- 2
- Forks
- 1
- Avg merge
- 6m
- Merged PRs (30d)
- 27
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sumamakhan761/tryinstance
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#65 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
sumamakhan761/tryinstance#64 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
sumamakhan761/tryinstance#63 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#62 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#60 ·
Maintainers usually reply within 1 day
All issues in sumamakhan761/tryinstance
Similar issues
-
prio:low scope:hud
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OliverRomhagen/vrigstad-joyride#953 ·
Maintainers usually reply within 1 day
-
review-followup
Difficulty 1/5 Under an hour Newbie friendliness 92/100
griffinwork40/agent-afk#5446 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
kacper-szewczyk/Ticknest#346 ·
Maintainers usually reply within 1 day
-
echarts geo: a GeoJSON URL that returns 200 with a body that is not JSON is fetched on each refreshOpenbug plugin/echarts/geo
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Yeachan-Heo/gajae-code#8230 ·
Maintainers usually reply within 1 day