﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	uname	nginx_version
1856	"Connection Reset due to ""unexpected range in slice response"" error"	x9e0319@…		"Dear *!
I m using Nginx to cache video files, which are delivered via http1.1 from a Java based backend Application.
Unfortunately, I am facing problems to request the final slice at the end of the video file from Nginx via byte range requests.
With the following curl command I m facing always connection resets triggered by Nginx.
{{{
    curl -v -I -X GET http://localhost:8080/APInoauth/storage/VX-1/file/VX-106339/0.9395159304006587/VX-106339.mp4 -H 'range: bytes=342130688-342300277'
}}}

Curl output: 
{{{
* Expire in 0 ms for 6 (transfer 0x560dda43b7a0)
* Expire in 1 ms for 1 (transfer 0x560dda43b7a0)
* Expire in 0 ms for 1 (transfer 0x560dda43b7a0)
* Expire in 1 ms for 1 (transfer 0x560dda43b7a0)
* Expire in 0 ms for 1 (transfer 0x560dda43b7a0)
* Expire in 0 ms for 1 (transfer 0x560dda43b7a0)
* Expire in 1 ms for 1 (transfer 0x560dda43b7a0)
* Expire in 0 ms for 1 (transfer 0x560dda43b7a0)
* Expire in 0 ms for 1 (transfer 0x560dda43b7a0)
* Expire in 1 ms for 1 (transfer 0x560dda43b7a0)
* Expire in 0 ms for 1 (transfer 0x560dda43b7a0)
* Expire in 0 ms for 1 (transfer 0x560dda43b7a0)
* Expire in 0 ms for 1 (transfer 0x560dda43b7a0)
*   Trying ::1...
* TCP_NODELAY set
* Expire in 150000 ms for 3 (transfer 0x560dda43b7a0)
* Expire in 200 ms for 4 (transfer 0x560dda43b7a0)
* connect to ::1 port 8080 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Expire in 150000 ms for 3 (transfer 0x560dda43b7a0)
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /APInoauth/storage/VX-1/file/VX-106339/0.9395159304006587/VX-106339.mp4 HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.64.0
> Accept: */*
> range: bytes=342130688-342300277
>
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server
}}}

The Nginx log file show the following error as reason for the reset.
{{{
2019/09/24 19:28:30 [debug] 7#7: *1188 http slice response range: 341835776-342884352/342300278
2019/09/24 19:28:30 [error] 7#7: *1188 unexpected range in slice response: 341835776-342884352 while reading response header from upstream, client: 127.0.0.1, server: , request: ""GET /APInoauth/storage/VX-1/file/VX-106339/0.9395159304006587/VX-106339.mp4 HTTP/1.1"", upstream: ""http://10.253.185.134:8080/APInoauth/storage/VX-1/file/VX-106339/0.9395159304006587/VX-106339.mp4"", host: ""localhost:8080""

}}}
-> rest of the debug log is attached

In the debug log I can see that the upstream server and Nginx have not the same view regarding the range request values, but actually I dont know which system delivers the correct range values.
It would be great to get some advice in which direction I should try to solve the issue.

Nginx Config
{{{
user  nginx;
worker_processes  2;
error_log  /var/log/nginx/error.log debug;
pid        /var/run/nginx.pid;
events {
  worker_connections  1024;
}
http {
  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;
  log_format rt_cache '$remote_addr - $upstream_cache_status [$time_local]  '
                      '""$request"" $status $body_bytes_sent '
                      '""$http_referer"" ""$http_user_agent""';
  log_format  main  '$remote_addr - $remote_user [$time_local] ""$request"" '
                    '$status $body_bytes_sent ""$http_referer"" '
                    '""$http_user_agent"" ""$http_x_forwarded_for""';
  access_log  /var/log/nginx/access.log  rt_cache;
  sendfile           on;
  aio                on;
  keepalive_timeout  65;
  proxy_buffering    on;
  proxy_buffer_size          128k;
  proxy_buffers              4 256k;
  proxy_busy_buffers_size    256k;
  include /etc/nginx/conf.d/*.conf;
}}}

/etc/nginx/conf.d/default.conf
{{{
proxy_cache_path /tmp/mediacache/level-1 keys_zone=cache-level-1:50m max_size=5g use_temp_path=on;
proxy_cache_path /tmp/mediacache/level-2 keys_zone=cache-level-2:50m max_size=5g use_temp_path=on;

server {
  listen        8080;
  server_name_in_redirect off;
  proxy_cache  cache-level-1;
  proxy_cache_valid 200 206 600s;
  # HTTP/1.0 does not support range requests
  proxy_http_version 1.1;

  add_header X-Proxy-Cache-1 $upstream_cache_status;

  # Bug fix to prevent IE11 from using gzip for video files
  #proxy_set_header Accept """";
  #proxy_set_header Accept-Encoding """";

  ### Caching Strategy Level 1: Cache Slice-by-Slice ####################################################################
    # Parameter takes care that only one caching request per resource is triggered
  proxy_cache_lock on;
    # Immediately forward requests to the origin if we are filling the cache
  proxy_cache_lock_timeout 0s;
    # Set the 'age' to a value larger than the expected fill time
  proxy_cache_lock_age 200s;
    # In case a cache update is running, use the currently cached version of the resource
  #proxy_cache_use_stale updating;

  slice              1m;
  proxy_cache_key    $host$uri$is_args$args$slice_range;
  proxy_set_header   Range $slice_range;
  ### End Caching Strategies ######################################################################################

  location /APInoauth {
    proxy_pass http://dev-distribution-vidispine:8080;
    lingering_close always;
  }
  location = /stub_status {
    stub_status;
  }
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
    root   /var/www/html;
  }
}
}}}"	defect	closed	major		nginx-module	1.17.x	invalid		Michael.Egbert@…	Linux dev-distribution-webcache-d5d87f7cb-h7gn5 5.1.1-1.el7.elrepo.x86_64 #1 SMP Sat May 11 09:15:02 EDT 2019 x86_64 Linux	"nginx version: nginx/1.17.2
built by gcc 8.3.0 (Alpine 8.3.0)
built with OpenSSL 1.1.1b  26 Feb 2019
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-threads --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-stream_realip_module --with-stream_geoip_module=dynamic --with-http_slice_module --with-mail --with-mail_ssl_module --with-compat --with-file-aio --with-http_v2_module
"
