0

i'm android developer and my application request to my server download a file

Log.d("SBP", f_url[0]);
URL url = new URL(f_url[0]);
URLConnection conection = url.openConnection();

in debuge show one request but in server when i open access.log i see 2 or more same request ! :|

but why???

this is my nginx.config

user  nginx;
worker_processes  1;
worker_rlimit_nofile 20000;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
 worker_connections  1024;
 }


http {
include       /etc/nginx/mime.types;
default_type  application/octet-stream;

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  main;

 sendfile        on;
 #tcp_nopush     on;

 keepalive_timeout  65;

 #gzip  on;

 include /etc/nginx/conf.d/*.conf;
 include /etc/nginx/sites-enabled/*;
 }

and it's my site config:

    server {
    server_name MYSITE;
    access_log /srv/www/MYSITE/logs/access.log;
    error_log /srv/www/MYSITE/logs/error.log;
    root /srv/www/MYSITE/public;

    client_max_body_size 20m;
    client_body_buffer_size 128k;

location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
    access_log        off;
    log_not_found     off;
    expires           360d;
}

    location / {
        index index.html index.htm index.php;
    }

location ~ /\. {
    access_log off;
    log_not_found off;
    deny all;
}

    location ~* \.php$ {
       # include /etc/nginx/fastcgi_params;
        server_tokens off;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        include         fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    }
}
  • Include access.log entries please. – Dmitry Verhoturov Feb 09 '15 at 06:44
  • MYIP - - [08/Feb/2015:22:28:39 +0330] "GET /api/v1/Download_File.php?id=9&type=mp3&filename=1.mp3&rquest=download HTTP/1.1" 200 344189 "-" "Dalvik/1.6.0 (Linux; U; Android 4.1.2; ST26i Build/11.2.A.0.31)" MYIP - - [08/Feb/2015:22:28:39 +0330] "GET /api/v1/Download_File.php?id=9&type=mp3&filename=1.mp3&rquest=download HTTP/1.1" 200 344189 "-" "Dalvik/1.6.0 (Linux; U; Android 4.1.2; ST26i Build/11.2.A.0.31)" – Mahdi.Zolqadr Feb 09 '15 at 14:20
  • @DmitryVerkhoturov: thanks. as u see 2 request insert into access.log and in my database increase download counter +2 – Mahdi.Zolqadr Feb 09 '15 at 14:22
  • Nothing to do with nginx, your code somewhy asking nginx for file twice. So, there is no point to include nginx configuration in question, better update it with well-formatted access.log entries. On your place I'll debug my code step by step to see where first and second request is processed. – Dmitry Verhoturov Feb 10 '15 at 07:11
  • @DmitryVerkhoturov : when Internet speed is low it's happen, and Volley send 2 or more same request. – Mahdi.Zolqadr Feb 11 '15 at 12:02

1 Answers1

0

Your problem is caused by Volley RetryPolicy. To fix it (as seen there and there) you need to disable retry attempts:

myRequest.setRetryPolicy(new DefaultRetryPolicy(
    DefaultRetryPolicy.DEFAULT_TIMEOUT_MS,
    0,
    DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

or increase timeout (10 seconds instead of default 2.5 in this example):

myRequest.setRetryPolicy(new DefaultRetryPolicy(
    DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 4,
    DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
    DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

More info about how RetryPolicy works can be found there, it's defaults can be found here.

Community
  • 1
  • 1
Dmitry Verhoturov
  • 5,835
  • 2
  • 32
  • 39