Skip to content

Add Publish Timeout on Disconnect#1001

Merged
mtmk merged 4 commits into
mainfrom
publish-timeout-after-disconnect
Dec 10, 2025
Merged

Add Publish Timeout on Disconnect#1001
mtmk merged 4 commits into
mainfrom
publish-timeout-after-disconnect

Conversation

@mtmk

@mtmk mtmk commented Nov 19, 2025

Copy link
Copy Markdown
Member

Put behind an option to not break existing behavior.

@mtmk
mtmk requested a review from scottf November 19, 2025 11:14

@scottf scottf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mtmk mtmk self-assigned this Nov 26, 2025
@mtmk mtmk added the priority label Nov 27, 2025
@mtmk

mtmk commented Dec 2, 2025

Copy link
Copy Markdown
Member Author

@paagamelo2 does this work for you?

@paagamelo2

Copy link
Copy Markdown

@paagamelo2 does this work for you?

Apologies, haven't had a chance to try this out yet. Will do between today and tomorrow!

@paagamelo2

Copy link
Copy Markdown

@mtmk I'm seeing the same behavior as before, despite using the new PublishTimeoutOnDisconnected flag.

I see in your tests you wait for the reconnection loop to kick in, which I don't. The only other difference is that I'm using Testcontainers. I'd be surprised if any of that makes a difference though.

This is essentially what I'm doing:

[Fact]
public async Task ExperimentWithRealNats()
{
    await using var nats = new NatsBuilder().Build();
    await nats.StartAsync();

    await using var client = new NatsClient(nats.GetConnectionString());
    var js = client.CreateJetStreamContext(new NatsJSOpts(new NatsOpts
    {
        CommandTimeout = TimeSpan.FromSeconds(3),
        PublishTimeoutOnDisconnected = true,
    }));

    await js.CreateStreamAsync(new StreamConfig("ORDERS", ["orders.>"]));

    await nats.StopAsync();

    try
    {
        await js.PublishAsync("orders.1", "this is my order :)");
    }
    catch (Exception ex)
    {
        Debugger.Break(); // <- never hit
    }
}

Do you spot anything wrong?

@mtmk

mtmk commented Dec 4, 2025

Copy link
Copy Markdown
Member Author

Thanks for checking this @paagamelo2

Can you try passing the opts to client:

    await using var client = new NatsClient(new NatsOpts
    {
        Url = nats.GetConnectionString(),
        CommandTimeout = TimeSpan.FromSeconds(3),
        PublishTimeoutOnDisconnected = true,
    });
    var js = client.CreateJetStreamContext();

@paagamelo2

Copy link
Copy Markdown

@mtmk cheers, that works as expected for me!

@mtmk
mtmk merged commit db9aacc into main Dec 10, 2025
30 of 33 checks passed
@mtmk
mtmk deleted the publish-timeout-after-disconnect branch December 10, 2025 11:16
mtmk added a commit that referenced this pull request Dec 11, 2025
* Add prioritized mode (#1011)
* Add Publish Timeout on Disconnect (#1001)
* Fix test flap (#1012)
* Add test to promote mirrored to regular stream (#1008)
* Add Nats-Expected-Last-Subject-Sequence-Subject (#1007)
* Fix keyed NATS clients with configurations (#1006)
* ensure NatsConnectionPool cannot overflow (#1005)
* Fix stream config adjustments on update (#995)
* Handel Unobserved Exceptions During Connection State Transitions (#999)
* Added verification of the consumer sequence number for pull ordered consumers (#981)
* Fix build warnings (#991)
* Reduce closure allocations (#988)
@mtmk mtmk mentioned this pull request Dec 11, 2025
mtmk added a commit that referenced this pull request Dec 11, 2025
* Add prioritized mode (#1011)
* Add Publish Timeout on Disconnect (#1001)
* Fix test flap (#1012)
* Add test to promote mirrored to regular stream (#1008)
* Add Nats-Expected-Last-Subject-Sequence-Subject (#1007)
* Fix keyed NATS clients with configurations (#1006)
* ensure NatsConnectionPool cannot overflow (#1005)
* Fix stream config adjustments on update (#995)
* Handel Unobserved Exceptions During Connection State Transitions (#999)
* Added verification of the consumer sequence number for pull ordered consumers (#981)
* Fix build warnings (#991)
* Reduce closure allocations (#988)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants