Particular / NServiceBus

Build, version, and monitor better microservices with the most powerful service platform for .NET
https://particular.net/nservicebus/
Other
2.07k stars 648 forks source link

Overriding the host name does not work consistently #7026

Open SzymonPobiega opened 3 months ago

SzymonPobiega commented 3 months ago

Describe the bug

Description

Overriding the hostname using the API introduced in NServiceBus 8

config.UniquelyIdentifyRunningInstance().UsingHostName("MyHost")

does not change the host name.

Expected behavior

Host name is set to the desired value.

Actual behavior

Host name (as obtained from the HostInformation public API) is not changed and always defaults to Environment.MachineName.

One of the places where this is clearly visible is the heartbeats feature. The heartbeat messages carry the wrong value.

Versions

The problem has been discovered in NServiceBus 8.2 but likely exists in all V8 and V9 versions

Steps to reproduce

  1. Override the host name using config.UniquelyIdentifyRunningInstance().UsingHostName("MyHost")
  2. Add the heartbeat plugin
  3. Run the endpoint using the Learning Transport
  4. Observe the Host filed in the heartbeat messages being set to the default value -- Environment.MachineName

Relevant log output

No response

Additional Information

Workarounds

The workaround in V8 is to use the legacy deprecated API:

#pragma warning disable CS0618 // Type or member is obsolete
RuntimeEnvironment.MachineNameAction = () => "MyMachine";
#pragma warning restore CS0618 // Type or member is obsolete

Possible solutions

Additional information

Combined with a bug in the heartbeat state machine handling in ServiceControl this issue leads to an endless loop of heartbeat stopped-heartbeat restored events generated by ServiceControl after one of the monitored endpoints is upgraded from NServiceBus 7 to NServiceBus 8 and re-deployed.