openresty / openresty/stream-lua-nginx-module

UDP Server lost packets

Open
#210 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
749
Forks
210
Avg merge
4h 31m
Merged PRs (30d)
3

Description

Hello, I'm trying to use openresty as a udp server. But some packets were lost.

Centos7
nginx version: openresty/1.17.8.2

  1. tcpdump: openresty received 3 packets, but only responded once
18:48:24.625532 IP 10.13.0.110.53193 > vmware.documentum: UDP, length 17
18:48:24.625568 IP 10.13.0.110.53193 > vmware.documentum: UDP, length 17
18:48:24.625571 IP 10.13.0.110.53193 > vmware.documentum: UDP, length 17
18:48:24.626090 IP vmware.documentum > 10.13.0.110.53193: UDP, length 17
  1. access.log: only 1
[28/Aug/2020:18:48:24 +0800] [2020-08-28T18:48:24+08:00] 10.13.0.110 - UDP 200 17 17 0.000 "-" "-" "-" "-"
  1. nginx.conf
user root;
worker_processes 1;
worker_cpu_affinity 01;
worker_rlimit_nofile 65535;
pid /run/nginx.pid;

events {
    worker_connections 65535;
    multi_accept on;
    use epoll;
}

stream {
    lua_code_cache on;

    log_format main '[$time_local] [$time_iso8601] $remote_addr - '
                     '$protocol $status $bytes_sent $bytes_received '
                     '$session_time "$upstream_addr" '
                     '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';

    access_log  /proj/log/access.log main;
    error_log   /proj/log/error.log debug;

    server {
        listen 10002 udp;
        content_by_lua_file src/udp.lua;
    }
}
  1. src/udp.lua
local sock, err = ngx.req.socket()
if not sock then
    ngx.log(ngx.ERR, string.format("get socket fail. err: %s", err))
    return
end

local data, err = sock:receive()
if not data then
    ngx.log(ngx.ERR, string.format("receive fail. err: %s", err))
    return
end

ngx.sleep(0)

sock:send(data)
  1. client.py
#!/bin/python

import socket
import ujson as json
import gevent
import random

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
addr = ("10.13.0.63", 10002)

for i in range(0, 3):
    sock.sendto(json.dumps({"idx": idx}), addr)
    # print(sock.recv(1024))

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with nginx.conf and src/udp.lua, then reproduce the behavior with client.py while comparing tcpdump and access.log. Trace how the UDP socket receives and sends the three datagrams; done means the reproduction accounts for all packets and the expected responses are restored or the loss is explained.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, nginx, python
Domain
backend, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.