Skip to content

Fix nf_conntrack table overflow causing UDP packet drops #72

@josecelano

Description

@josecelano

Relates to: #26 (comment)

Problem Description

The tracker is experiencing low uptime on newtrackon.com. It could be due to UDP packet drops caused by the Linux netfilter connection tracking (nf_conntrack) table becoming full. This is evidenced by kernel messages showing:

nf_conntrack: nf_conntrack: table full, dropping packet

This issue was discovered while investigating the tracker uptime problem reported in issue #26, specifically detailed in this comment.

Evidence from System Logs

The following kernel messages show the nf_conntrack table overflow:

sudo journalctl -k | grep -i 'udp\|drop\|icmp'
[sudo] password for torrust: 
Jun 17 17:39:30 torrust-demo kernel: DMI: DigitalOcean Droplet/Droplet, BIOS 20171212 12/12/2017
Jun 17 17:39:30 torrust-demo kernel: UDP hash table entries: 4096 (order: 5, 131072 bytes, linear)
Jun 17 17:39:30 torrust-demo kernel: UDP-Lite hash table entries: 4096 (order: 5, 131072 bytes, linear)
Jun 17 17:39:30 torrust-demo kernel: drop_monitor: Initializing network drop monitor service
Jun 17 18:44:13 torrust-demo kernel: nf_conntrack: nf_conntrack: table full, dropping packet
Jun 17 18:49:13 torrust-demo kernel: nf_conntrack: nf_conntrack: table full, dropping packet
Jun 17 18:50:11 torrust-demo kernel: nf_conntrack: nf_conntrack: table full, dropping packet
Jun 17 19:27:38 torrust-demo kernel: nf_conntrack: nf_conntrack: table full, dropping packet
Jun 17 19:34:48 torrust-demo kernel: nf_conntrack: nf_conntrack: table full, dropping packet
Jun 17 19:46:51 torrust-demo kernel: nf_conntrack: nf_conntrack: table full, dropping packet
Jun 17 19:51:47 torrust-demo kernel: nf_conntrack: nf_conntrack: table full, dropping packet

Connection tracking statistics show high early_drop counts and search_restart values, indicating table pressure:

sudo conntrack -S
cpu=0   	found=0 invalid=156 insert=0 insert_failed=0 drop=0 early_drop=814 error=0 search_restart=5374122 (null)=0 (null)=0 
cpu=1   	found=0 invalid=168 insert=0 insert_failed=0 drop=0 early_drop=681 error=0 search_restart=5388730 (null)=0 (null)=0 
cpu=2   	found=0 invalid=190 insert=0 insert_failed=0 drop=0 early_drop=1058 error=0 search_restart=5092846 (null)=0 (null)=0 
cpu=3   	found=562 invalid=27152 insert=0 insert_failed=135 drop=237 early_drop=26755924 error=5 search_restart=503791899 (null)=2539351 (null)=0

Impact

  • UDP tracker requests are being dropped at the kernel level
  • This causes timeouts from monitoring services like newtrackon.com
  • Results in poor uptime statistics (currently around 90% instead of target 95%+)
  • Prevents the tracker from being included in the newtrackon.com public tracker list

Proposed Solution

Configure the Linux system to handle the high UDP connection load by adjusting netfilter connection tracking parameters:

1. Increase nf_conntrack table size

# Check current values
cat /proc/sys/net/netfilter/nf_conntrack_max
cat /proc/sys/net/netfilter/nf_conntrack_buckets

# Increase the maximum number of connections (e.g., to 262144)
echo 'net.netfilter.nf_conntrack_max = 262144' >> /etc/sysctl.conf

# Increase hash table buckets (should be max/4)
echo 'net.netfilter.nf_conntrack_buckets = 65536' >> /etc/sysctl.conf

2. Reduce connection tracking timeout for UDP

# Reduce UDP timeout from default 30s to 10s for faster cleanup
echo 'net.netfilter.nf_conntrack_udp_timeout = 10' >> /etc/sysctl.conf
echo 'net.netfilter.nf_conntrack_udp_timeout_stream = 10' >> /etc/sysctl.conf

3. Alternative: Disable connection tracking for tracker port

If connection tracking is not needed for the tracker service, we could disable it specifically for the tracker port:

# Add iptables rules to disable connection tracking for UDP port 6969
iptables -t raw -A PREROUTING -p udp --dport 6969 -j NOTRACK
iptables -t raw -A OUTPUT -p udp --sport 6969 -j NOTRACK

4. Apply changes

# Apply sysctl changes
sysctl -p

# Make iptables rules persistent (if using option 3)
iptables-save > /etc/iptables/rules.v4

Monitoring

After implementing the fix, monitor:

  • Kernel logs for nf_conntrack messages: sudo journalctl -k | grep nf_conntrack
  • Connection tracking statistics: sudo conntrack -S
  • Tracker uptime on newtrackon.com

References

Priority

High - This directly affects the tracker's availability and prevents inclusion in public tracker lists.

cc @da2ce7

Metadata

Metadata

Assignees

Labels

- Admin -Enjoyable to Install and Setup our Software

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions