I found a bug that is still open from May 2010 and describes the same behaviour that I see with my application:
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=146845 If this hasn't been fixed over the last 14 years, then I guess I will add some code to simply ignore ECONNRESET on close(2) for FreeBSD and MacOS. This seems the be the general advice from other people who hit this issue.