dapr / dapr/js-sdk

publishBulk silently fails on HTTP 500 errors - returns empty failedMessages array

Open
#703 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
217
Forks
104
PR merge metrics
No merged PRs in 30d

Description

## Bug Description

The `publishBulk` method in the Dapr Node.js SDK has a critical error handling bug where it returns `{ failedMessages: [] }` instead of actual failed entries when the Dapr sidecar returns HTTP 500 errors. This causes applications to incorrectly assume bulk publish operations succeeded when they actually failed.

## Environment

- **Dapr Runtime Version**: v1.15.5
- **Dapr JS SDK Version**: v3.5.2 (latest)
- **Node.js Version**: v18+
- **Platform**: macOS/Linux

## Expected Behavior

When `publishBulk` encounters HTTP 500 errors from the Dapr sidecar, it should return a response with populated `failedMessages` array containing the actual failed entries.

## Actual Behavior

The SDK returns `{ failedMessages: [] }` even when all messages fail to publish, causing applications to incorrectly assume success.

## Root Cause

The bug is in the `handleBulkPublishError` method in `/implementation/Client/HTTPClient/pubsub.js` (lines 65-77). The method fails to properly parse HTTP 500 error responses from the Dapr sidecar.

**Problematic code:**
```javascript
async handleBulkPublishError(entries, error) {
try {
const err = JSON.parse(error.message);
if (err.error_msg) {
const bulkPublishResponse = JSON.parse(err.error_msg);
return (0, Client_util_1.getBulkPublishResponse)({ entries: entries, response: bulkPublishResponse });
}
}
catch (_innerError) {
// Falls through to return empty failedMessages
}
return (0, Client_util_1.getBulkPublishResponse)({ entries: entries, error: error });
}
```

## Reproduction Steps

1. Configure Dapr with a Kafka pubsub component
2. Use `publishBulk` with an invalid/non-existent topic name
3. Observe that Dapr sidecar correctly returns HTTP 500 with error details
4. Check the SDK response - it returns `{ failedMessages: [] }`

## Logs Evidence

**Dapr sidecar correctly detects error:**
```
DEBU[13082] api error: code = Internal desc = error when publishing to topic foo in pubsub pub-sub-kyc3: kafka: Failed to deliver 1 messages.
INFO[13082] HTTP API Called ... code=500 duration=1358 ... size=207
```

**SDK incorrectly returns empty failedMessages:**
```javascript
Dapr publishBulk result: { failedMessages: [] }
```

## Impact

This is a **critical bug** that causes:
- Silent failures in production systems
- Data loss (messages appear published but aren't)
- Incorrect application state (success reported when operations fail)
- Difficult debugging (no indication of failure in application logs)

## Workaround

Currently, applications must implement additional error detection by:
1. Monitoring Dapr sidecar logs directly
2. Implementing custom timeout/retry logic
3. Using alternative publish methods

## Suggested Fix

The `handleBulkPublishError` method needs to properly parse the HTTP 500 error response structure that Dapr returns. The error response contains valid `failedEntries` data that should be extracted and returned to the application.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.