Skip to content

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

@spolom

Description

@spolom

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:

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions