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
IBus.OutgoingHeaders updates can cause InvalidOperationException #1976
Comments
Will this still be a problem when #1975 is fixed (ie the headers will no longer change after config time)? |
@chrisbednarski we are still discussing whether the global headers should be changed after configuration or not, please comment with your opinion |
I currently don't have any use-cases for modifying the global All I was saying, I don't see any benefit in making the global header access thread safe, if headers cannot be modified after Bus has been started. It would make sense to do either one or the other. On another note, it's feasible to atomically replace the entire collection using pseudo code
|
We set the outgoing headers on every message. |
There are 2 use cases:
To do case 1, you should set the global headers in a class Foo : IWantToRunWhenBusStartsAndStops
{
public IBus Bus { get; set; }
public void Start()
{
Bus.OutgoingHeaders.Add("MyGlobalKey", "MyGlobalValue");
}
public void Stop()
{
}
} To do case 2, you set those headers in a public class MyMessageHandler : IHandleMessages<MyMessage>
{
public IBus Bus { get; set; }
public void Handle(MyMessage msg)
{
MyOutgoingMessage message = new MyOutgoingMessage();
Bus.SetMessageHeader(message, "MyKeyForThisMessage", "My special value for this message");
Bus.Send(message);
//More code
}
} |
Thanks. I misunderstood in #1975 when someone said they couldn't think of a use case where changing the headers would be a good idea. I was saying that we did change them. I thought I had put the comment on the other ticket. I missed the distinction between global outgoing headers and outgoing headers. So I think I understand that now. In your example you say to use Bus.OutgoingHeaders.Add("MyGlobalKey", "MyGlobalValue"); I thought we were supposed to use the Set method here as well because of the bug. |
related to #1975 |
so the short term fix for the actually issue outline here to change the storage of these headers to a Any objections? |
go ahead On Sun, Oct 19, 2014 at 1:27 AM, Simon Cropp notifications@github.com
|
Change
IBus.OutgoingHeaders
to aConcurrentDictionary
Because the framework allows a user to modify
IBus.OutgoingHeaders
during runtime and those headers are global, an InvalidOperationException (Collection was modified; enumeration operation may not execute.) can be thrown during enumeration of those headers dictionary.So a possible solution is to make a copy of the dictionary every time before enumerating it.
The code in question is https://github.com/Particular/NServiceBus/blob/develop/src/NServiceBus.Core/Unicast/Behaviors/CreatePhysicalMessageBehavior.cs#L37
The text was updated successfully, but these errors were encountered: