Skip to content

NetworkTarget with TCP KeepConnection=true should retry on error #1

@MikeFH

Description

@MikeFH

When using the NetworkTarget with the KeepConnection=true, the connection to the server is kept open so that it can be reused. Using the TCP protocol, if the server is configured to close the connection after a period of inactivity (a common configuration to avoid DOS), we then have a NetworkSender holding a closed Socket. The problem is that it seems that the next log message we try to send will not be received by the server (executing https://github.com/NLog/NLog/blob/master/src/NLog/Targets/NetworkTarget.cs#L291).

One workaround would be to set KeepConnection=false but in case of a TCP connection this can be expensive when the application starts to write more logs.
Another solution would be to use RetryingTargetWrapper, but it seems a bit odd to configure a retry for that particular case since no error really occurred.

So do you think it is possible to check the status of the socket before using it to send the message and try to open a new one in case it was cleanly closed by the server ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions