Error in ssl_pthread_server example and/or mbedtls_net_accept library

I modeled my simple client after the example ssl_pthread_server but noticed some strange behavior. Each connection that comes in causes mbedtls_net_accept to return twice for that connection. One will eventually fail to read data, but it still causes two complete runs through the thread creation, ssl setup, ssl handshake etc.

So I went and ran the ssl_pthread_server example as built by mbedtls-2.2.1 and it exhibited the exact same behavior. Output from ssl_pthread_server shown below.

Is this a bug in the example or the library or??

Any help appreciated,
Deron


./ssl_pthread_server

. Loading the server cert. and key… ok
. Seeding the random number generator… ok
. Setting up the SSL data… ok
. Bind on https://localhost:4433/ … ok
[ main ] Waiting for a remote connection
[ main ] ok
[ main ] Creating a new thread
[ main ] Waiting for a remote connection
[ main ] ok
[ main ] Creating a new thread
[ main ] Waiting for a remote connection
[ #139733925684992 ] Setting up SSL/TLS data
[ #139733917292288 ] Setting up SSL/TLS data
[ #139733925684992 ] Performing the SSL/TLS handshake
[ #139733917292288 ] Performing the SSL/TLS handshake
[ #139733925684992 ] ok
[ #139733925684992 ] < Read from client
[ #139733917292288 ] ok
[ #139733917292288 ] < Read from client
[ #139733925684992 ] 323 bytes read

GET / HTTP/1.1
Host: mydomain.com:4433
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:43.0) Gecko/20100101 Firefox/43.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cache-Control: max-age=0

=====
[ #139733925684992 ] > Write to client:
[ #139733925684992 ] 147 bytes written

HTTP/1.0 200 OK
Content-Type: text/html

mbed TLS Test Server

Successful connection using: TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA

=====
[ #139733925684992 ] . Closing the connection… ok
[ #139733917292288 ] connection was closed gracefully
[ #139733917292288 ] Last error was: -0x7880 - SSL - The peer notified us that the connection is going to be closed