Pavel Punsky 01f58677b6 examples: actively wait for turnserver init instead of static sleep
The sanitize CI job (clang.yml's ASan/TSan matrix) was failing on the
TCP test with "Connect: Connection refused". Root cause: ASan- and
TSan-instrumented turnserver routinely takes 5-10s before it binds
3478, but the test scripts only sleep 2-5s before launching uclient.
Master got away with this because the uninstrumented Linux build
binds in milliseconds.

Replace the static sleep with an active probe of OUR turnserver
instance's log file (uniquely named via $$). Once "Total relay
threads:" appears -- which netengine.c emits near the end of init --
the listener is ready and we can run uclient. Caps at 20s; if either
backing process dies before that, fail fast with the actual log
content rather than letting a per-protocol FAIL paper over the
startup problem.

The probe has to read OUR log, not /dev/tcp/127.0.0.1/3478, because a
prior script's dying turnserver can still answer the bash connect()
probe long enough to give a false positive in back-to-back runs.

This required forcing turnserver's log to stdout (where our redirect
captures it):

  - run_tests.sh:      added --log-file=stdout --simple-log
  - run_tests_conf.sh: added log-file=stdout / simple-log to the conf

Without that, turnserver writes to its platform-default location
(syslog or /var/log/turn_*.log) and the redirected file stays empty,
which both breaks the wait probe and makes the FAIL diagnostics
useless. Master's `> /dev/null` accidentally worked only because
nothing was reading stdout anyway.

Diagnostic dump also disambiguates "log exists but is empty" from
"log file missing" so future failures don't read as ambiguous.

Validated in Linux Docker: 9/9 OK in each script, run back-to-back
in the same shell (so a SIGPIPE-killed prior script can't leave a
ghost turnserver to confuse the next one).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 22:53:21 -07:00
2026-01-05 17:35:27 -08:00
2026-04-27 08:34:38 -07:00
2026-04-13 15:16:42 -07:00
2026-05-04 18:55:49 -07:00
2026-05-08 22:47:46 -07:00
2023-01-09 19:27:00 +01:00
2014-04-20 21:10:18 +00:00
2017-02-20 01:10:38 -08:00
2026-04-27 08:34:38 -07:00
2025-09-05 10:37:58 -07:00
2026-05-08 22:47:46 -07:00
2025-05-30 14:13:59 -07:00
2026-01-05 17:35:27 -08:00

Docker CI Docker Hub Fuzzing Status

Docker Hub | GitHub Container Registry | Quay.io

Coturn TURN server

coturn is a free open source implementation of TURN and STUN Server. The TURN Server is a VoIP media traffic NAT traversal server and gateway.

Installing / Getting started

Linux distros may have a version of coturn which you can install by

apt install coturn
turnserver --log-file stdout

Or run coturn using docker container:

docker run -d -p 3478:3478 -p 3478:3478/udp -p 5349:5349 -p 5349:5349/udp -p 49152-65535:49152-65535/udp coturn/coturn

See more details about using docker container Docker Readme

Developing

Dependencies

coturn requires following dependencies to be installed first

  • libevent2

Optional

  • openssl (to support TLS and DTLS, authorized STUN and TURN)
  • libmicrohttp and prometheus-client-c (prometheus interface)
  • MariaDB/MySQL (user database)
  • Hiredis (user database, monitoring)
  • SQLite (user database)
  • PostgreSQL (user database)

Building

git clone git@github.com:coturn/coturn.git
cd coturn
./configure
make

Features

STUN specs:

  • RFC 3489 - "classic" STUN
  • RFC 5389 - base "new" STUN specs
  • RFC 5769 - test vectors for STUN protocol testing
  • RFC 5780 - NAT behavior discovery support
  • RFC 7443 - ALPN support for STUN & TURN
  • RFC 7635 - oAuth third-party TURN/STUN authorization

TURN specs:

ICE and related specs:

The implementation fully supports the following client-to-TURN-server protocols:

Relay protocols:

User databases (for user repository, with passwords or keys, if authentication is required):

  • SQLite
  • MariaDB/MySQL
  • PostgreSQL
  • Redis
  • MongoDB

Management interfaces:

  • telnet cli
  • HTTPS interface

Monitoring:

  • Redis can be used for status and statistics storage and notification
  • prometheus interface (unavailable on apt package)

Message integrity digest algorithms:

  • HMAC-SHA1, with MD5-hashed keys (as required by STUN and TURN standards)

TURN authentication mechanisms:

  • 'classic' long-term credentials mechanism;
  • TURN REST API (a modification of the long-term mechanism, for time-limited secret-based authentication, for WebRTC applications: http://tools.ietf.org/html/draft-uberti-behave-turn-rest-00);
  • experimental third-party oAuth-based client authorization option;

Performance and Load Balancing:

When used as a part of an ICE solution, for VoIP connectivity, this TURN server can handle thousands simultaneous calls per CPU (when TURN protocol is used) or tens of thousands calls when only STUN protocol is used. For virtually unlimited scalability a load balancing scheme can be used. The load balancing can be implemented with the following tools (either one or a combination of them):

  • DNS SRV based load balancing;
  • built-in 300 ALTERNATE-SERVER mechanism (requires 300 response support by the TURN client);
  • network load-balancer server.

Traffic bandwidth limitation and congestion avoidance algorithms implemented.

Target platforms:

  • Linux (Debian, Ubuntu, Mint, CentOS, Fedora, Redhat, Amazon Linux, Arch Linux, OpenSUSE)
  • BSD (FreeBSD, NetBSD, OpenBSD, DragonFlyBSD)
  • Solaris 11
  • Mac OS X
  • Cygwin (for non-production R&D purposes)
  • Windows (native with, e.g., MSVC toolchain)

This project can be successfully used on other *NIX platforms, too, but that is not officially supported.

The implementation is supposed to be simple, easy to install and configure. The project focuses on performance, scalability and simplicity. The aim is to provide an enterprise-grade TURN solution.

To achieve high performance and scalability, the TURN server is implemented with the following features:

  • High-performance industrial-strength Network IO engine libevent2 is used
  • Configurable multi-threading model implemented to allow full usage of available CPU resources (if OS allows multi-threading)
  • Multiple listening and relay addresses can be configured
  • Efficient memory model used
  • The TURN project code can be used in a custom proprietary networking environment. In the TURN server code, an abstract networking API is used. Only couple files in the project have to be re-written to plug-in the TURN server into a proprietary environment. With this project, only implementation for standard UNIX Networking/IO API is provided, but the user can implement any other environment. The TURN server code was originally developed for a high-performance proprietary corporate environment, then adopted for UNIX Networking API
  • The TURN server works as a user space process, without imposing any special requirements on the system
S
Description
No description provided
Readme BSD-3-Clause 12 MiB
Languages
C 90.5%
CMake 4.1%
Shell 2.1%
C++ 1.5%
Makefile 1%
Other 0.7%