nathanaelle / syslog5424

log.Logger-friendly RFC-5424 syslog library
BSD 2-Clause "Simplified" License
6 stars 1 forks source link

syslog.Dial doesn't return error on closed tcp port #7

Closed DavidGamba closed 6 years ago

DavidGamba commented 6 years ago

When I try to send a message on a closed syslog server I can't handle the error because Dial is not providing any errors indicating that the socket is closed.

I only get a failure when sending a message but I can't find a way to get an error from it to handle it.

This is what I get before my code exits:

2017/11/02 14:08:26 dial tcp [::1]:5140: getsockopt: connection refused
nathanaelle commented 6 years ago

the real Dial is call in a goroutine. I don't use directly a net.Conn but I use an interface that provide a Redial() func.

I need to think for a way to provide some feed back.

nathanaelle commented 6 years ago

I may have a solution … I will write it on monday.

nathanaelle commented 6 years ago

I didn't forget…

I must correct 1 remaining error before pushing the code.

nathanaelle commented 6 years ago

my misconception (exactly a forgotten TODO) is trivial here :

  1. it's a TODO , so let's do it later (and forget it)
  2. if an error occurs in a goroutine, there is no way to get it except with the panic/defer/recover pattern.

the coded solution is :

  1. rewrite the code, and introduce some breaking change in the creation
  2. provide wrapper to ease the migration with the breaking change
  3. provide a chan error so you can catch any error in goroutine and decide what to do with them
nathanaelle commented 6 years ago

two panic() remain in listener-unixgram.go . there is a new issue with unixgram collector because, unixgramdoesn't support writev() syscall (introduced with my rewrite).

I want to drop the unixgram code but unixgram are AF_UNIX Datagram (UDP equivalent) and some unix systems still need them in 2017 😤

nathanaelle commented 6 years ago

if the code is fine for you, I will correct the import paths and release it as v0.2