Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PublishConfirmException when doing RPC before publishing a message. #274

Closed
jayrulez opened this issue Sep 26, 2017 · 9 comments
Closed

Comments

@jayrulez
Copy link
Contributor

jayrulez commented Sep 26, 2017

PublishConfirmException: The broker did not send a publish acknowledgement for message 1 within xx

Error occurs when doing a request immediately before publishing a message.

This test app reproduces the error:

https://github.com/SenitCorp/SenitTest

run the api and browse /api/values

If the order of the statements are changed to put the RPC first then everything works fine.

@jayrulez jayrulez changed the title PublishConfirmException when doing RPC after publishing a message. PublishConfirmException when doing RPC beforepublishing a message. Sep 26, 2017
@jayrulez jayrulez changed the title PublishConfirmException when doing RPC beforepublishing a message. PublishConfirmException when doing RPC before publishing a message. Sep 26, 2017
@pardahlman
Copy link
Owner

Hi @jayrulez - thanks for reporting this, I'll try to reproduce it in your sample code and see what can be done about it!

@jayrulez
Copy link
Contributor Author

@pardahlman I seem to have figured out the issue. It's not a problem with RawRabbit per se.

I was returning the wrong type Task.FromResult(0) instead of Task.CompletedTask from my event handler.

I don't know if there was anyway RawRabbit could know what's wrong there.

Any way, we can consider this solved unless you have any input.

Regards.

@jayrulez
Copy link
Contributor Author

False positive.

The error is still there.

Not sure why it worked once and just stopped.

I have updated the test app.

Try /test1 /test2 /test3 and /test4 to see the results.

Regards.

@pardahlman
Copy link
Owner

Hi again @jayrulez,

I tried reproduce this in the sample app by injecting a publish right after the RPC request

var response = await _busClient.RequestAsync<ValueRequest, ValueResponse>(new ValueRequest {Value = id});
await _busClient.PublishAsync(new TestMessage());

...and this worked as expected. I haven't had time to setup your application, but I wonder if it might have something to do with the application setup 🤔 . It would be helpful if you could create a minimal sample where this occurs. You might even be able to change the sample in the RawRabbit solution to get in the faulty state?

@jayrulez
Copy link
Contributor Author

jayrulez commented Oct 2, 2017

Please see 8ca32e7 for reproducing the issue.

Maybe you are not able to reproduce it because you have consumer and producer in a different process.

@jayrulez
Copy link
Contributor Author

jayrulez commented Oct 6, 2017

@pardahlman any thoughts?

@pardahlman
Copy link
Owner

Hello @jayrulez - sorry, not yet. I have had a lot on my plate but will hopefully be able to give this some attention soon

@pardahlman
Copy link
Owner

Hello again,

I can reproduce this. It took some time, as I had to figure out what happened in the example code. After a while I could isolate it to an integration test, see below

[Fact]
public async Task Throws_Publish_Confirm_Exception_If_Rpc_Response_Sent()
{
  using (var client = RawRabbitFactory.CreateTestClient())
  {
    // Setup 
    await client.RespondAsync<BasicRequest, BasicResponse>(request => Task.FromResult(new BasicResponse()));
    await client.RequestAsync<BasicRequest, BasicResponse>(new BasicRequest());

    try
    {
      // Test
      await client.PublishAsync(new BasicMessage());
    }
    catch (PublishConfirmException e)
    {
      // Assert
      Assert.True(false, e.Message);
    }
    Assert.True(true);
  }
}

The problem is not that the request is performed just before the publish, but that the same client publishes the response before the request is published. When debugging the code, I noticed a strange behavior in the underlying IModel; it's NextPublishSeqNo gets out-of-sync with +1 for each response produced. My theory ATM is that it has to do with execution in multiple threads. Will continue to look into this.

pardahlman added a commit that referenced this issue Oct 9, 2017
To catch problem with respond and publish
@pardahlman
Copy link
Owner

Hello, @jayrulez - this is fixed in rc1 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants