Commit Graph

1331 Commits

Author SHA1 Message Date
Max Romanov
89b1e88f8f Closing unsent file descriptors from port queue.
After a process exits, all ports linked to it from other processes
should be closed.  All unsent file descriptors in port queue, marked as
"close after send", should be closed to avoid resource leakage.
2020-05-28 12:40:49 +03:00
Valentin Bartenev
b2e6ef7beb Static: fixed potential undefined behavior in memcpy().
According to the C standard, pointer arguments passed to memcpy() calls shall
still have valid values.  NULL is considered as invalid.

Found with GCC Static Analyzer.
2020-05-20 11:18:03 +03:00
Remi Collet
140b81208e PHP: building with PHP 8 (development version). 2020-05-20 11:18:03 +03:00
Valentin Bartenev
d0de6df839 Fixed global constant declaration (appeared in 9af10e099d09).
This fixes building with GCC 10, which is default to -fno-common.
See: https://gcc.gnu.org/gcc-10/porting_to.html
2020-05-15 21:32:07 +03:00
Valentin Bartenev
79f5e531fe Router: removed two unused assignments.
This should resolve some static analyzers warnings.
2020-05-15 17:08:37 +03:00
Axel Duch
ee1e248f4b Router: decode uri and args. 2020-05-14 12:29:06 +02:00
Valentin Bartenev
376d758dd7 PHP: implemented "targets" option.
This allows to specify multiple subsequent targets inside PHP applications.
For example:

  {
      "listeners": {
          "*:80": {
              "pass": "routes"
          }
      },

      "routes": [
          {
              "match": {
                  "uri": "/info"
              },

              "action": {
                  "pass": "applications/my_app/phpinfo"
              }
          },
          {
              "match": {
                  "uri": "/hello"
              },

              "action": {
                  "pass": "applications/my_app/hello"
              }
          },
          {
              "action": {
                  "pass": "applications/my_app/rest"
              }
          }
      ],

      "applications": {
          "my_app": {
              "type": "php",
              "targets": {
                  "phpinfo": {
                      "script": "phpinfo.php",
                      "root": "/www/data/admin",
                  },

                  "hello": {
                      "script": "hello.php",
                      "root": "/www/data/test",
                  },

                  "rest": {
                      "root": "/www/data/example.com",
                      "index": "index.php"
                  },
              }
          }
      }
  }
2020-05-14 13:15:01 +03:00
Valentin Bartenev
0174c971b5 Configuration: URI encoding in the "pass" option.
This is useful to escape "/" in path fragments.  For example, in order
to reference the application named "foo/bar":

  {
      "pass": "applications/foo%2Fbar"
  }
2020-05-14 13:15:00 +03:00
Max Romanov
3ec72362b9 Waiting for router instead of reporting to user on config update. 2020-05-12 16:25:24 +03:00
Max Romanov
50f9816daa Blocking config change when applying the initial router config. 2020-05-12 16:25:16 +03:00
Max Romanov
6bda9b5eeb Using malloc/free for the http fields hash.
This is required due to lack of a graceful shutdown: there is a small gap
between the runtime's memory pool release and router process's exit. Thus, a
worker thread may start processing a request between these two operations,
which may result in an http fields hash access and subsequent crash.

To simplify issue reproduction, it makes sense to add a 2 sec sleep before
exit() in nxt_runtime_exit().
2020-04-16 17:09:23 +03:00
Igor Sysoev
ee62736a11 Fixed memory leak occurring upon failure to accept a connection. 2020-04-15 15:10:14 +03:00
Igor Sysoev
04143c8c7e Fixed crash that occurs when idle connections are closed forcibly. 2020-04-15 14:54:09 +03:00
Igor Sysoev
e616d0915c Disabled epoll error processing when socket events are inactive. 2020-04-15 14:54:09 +03:00
Max Romanov
9a422b8984 Completing chained shared memory buffers.
After 41331471eee7 completion handlers should complete next buffer in chain.
Otherwise buffer memory may leak.

Thanks to Peter Tkatchenko for reporing the issue and testing fixes.
2020-04-14 16:11:13 +03:00
Max Romanov
58cc13ab29 Resolving a racing condition while adding ports on the app's side.
An earlier attempt (ad6265786871) to resolve this condition on the
router's side added a new issue: the app could get a request before
acquiring a port.
2020-04-10 16:21:58 +03:00
Valentin Bartenev
c7f5c1c664 Controller: improved handling of unix domain control socket.
One of the ways to detect Unit's startup and subsequent readiness to accept
commands relies on waiting for the control socket file to be created.
Earlier, it was unreliable due to a race condition between the client's
connect() and the daemon's listen() calls after the socket's bind() call.

Now, unix domain listening sockets are created with a nxt_listen_socket_create()
call as follows:

   s = socket();
   unlink("path/to/socket.tmp")
   bind(s, "path/to/socket.tmp");
   listen(s);
   rename("path/to/socket.tmp", "path/to/socket");

This eliminates a time-lapse when the socket file is already created but nobody
is listening on it yet, which therefore prevents the condition described above.

Also, it allows reliably detecting whether the socket is being used or simply
wasn't cleaned after the daemon stopped abruptly.  A successful connection to
the socket file means the daemon has been started; otherwise, the file can be
overwritten.
2020-04-08 15:15:24 +03:00
Valentin Bartenev
a6d9efcee1 Controller: fixed cleaning up of control socket file in some cases.
Previously, the unix domain control socket file might have been left
in the file system after a failed nxt_listen_socket_create() call.
2020-04-08 15:15:24 +03:00
Valentin Bartenev
555d595f38 Removed unused code related to testing of address binding. 2020-04-08 15:15:24 +03:00
Valentin Bartenev
27c1e26856 Controller: eliminated extra control socket's sockaddr copying. 2020-04-08 15:15:24 +03:00
Max Romanov
ce53d6bdb1 Node.js: fixing Server.listen() method.
This is required for Express framework compatibility.

This closes #418 issue on GitHub.
2020-04-08 14:44:53 +03:00
Max Romanov
792ef9d3c7 Fixing 'find & add' racing condition in connected ports hash.
Missing error log messages added.
2020-04-06 16:52:11 +03:00
Valentin Bartenev
be943c9fd4 Fixed build with Clang 10, broken by 32578e837322.
This silences the -Wimplicit-int-float-conversion warning.
2020-04-01 18:33:48 +03:00
Igor Sysoev
01e957ef64 Rational number support in upstream server weight. 2020-03-30 19:47:01 +03:00
Valentin Bartenev
68c6b67ffc Configuration: support for rational numbers. 2020-03-30 19:37:58 +03:00
Max Romanov
0935630cba Fixing application process infinite loop.
Main process exiting before app process init may have caused hanging.
2020-03-30 14:18:51 +03:00
Max Romanov
ab7b42a072 Handling change file message in libunit.
This is required for proper log file rotation action.
2020-03-30 14:18:41 +03:00
Max Romanov
82b899b136 Attributing libunit logging function for arguments validation. 2020-03-30 14:08:20 +03:00
Valentin Bartenev
c63b498f94 Implemented "location" option for "return" action.
This allows to specify redirects:

  {
      "action": {
          "return": 301,
          "location": "https://www.example.com/"
      }
  }
2020-03-21 01:39:00 +03:00
Valentin Bartenev
35d6f84426 Added nxt_is_complex_uri_encoded()/nxt_encode_complex_uri(). 2020-03-27 17:22:52 +03:00
Valentin Bartenev
d4b4cb0438 Updated URI escaping table for better conformity with RFC 3986.
Now '>', '<', '"', '^', '\', '}', '|', '{', and '`' are also escaped.
2020-03-27 17:22:52 +03:00
Valentin Bartenev
8d727774e3 Implemented "return" action.
The "return" action can be used to immediately generate a simple HTTP response
with an arbitrary status:

  {
      "action": {
          "return": 404
      }
  }

This is especially useful for denying access to specific resources.
2020-03-27 17:22:52 +03:00
Valentin Bartenev
5f9c4754cb Initialization of the action object made more consistent. 2020-03-27 17:22:52 +03:00
Valentin Bartenev
fd8e524b82 Configuration: fixed comments parsing.
Unclosed multi-line comments and "/" at the end of JSON shouldn't be allowed.
2020-03-25 19:14:15 +03:00
Max Romanov
59e06e4910 Completing buffers immediately
This fixes crash introduced in 039b00e32e3d.
2020-03-19 22:04:43 +03:00
Max Romanov
c26fbbe53a Completing request header buffers to avoid memory leak.
Before this fix, only persistent connection request buffers were completed.

This issue was introduced in dc403927ab0b.
2020-03-19 20:43:35 +03:00
Max Romanov
c6f9ca79e6 Fixing body fd access racing condition.
To avoid closing the body fd prematurely, the fd value is moved from
the request struct to the app link.  The body fd should not be closed
immediately after the request is sent to the application due to possible
request rescheduling.
2020-03-17 14:44:11 +03:00
Max Romanov
5296be0b82 Using disk file to store large request body.
This closes #386 on GitHub.
2020-03-12 17:54:29 +03:00
Max Romanov
08b65721e2 Moving request memory pool retain call after RPC data allocation.
If the call is done only after a successful RPC data allocation, its
corresponding release call is not missed, which avoids a potential leak.
2020-03-12 17:54:24 +03:00
Max Romanov
0b5aabfc3f Checking Content-Length value right after header parse.
The check was moved from the request body read stage.
2020-03-12 17:54:19 +03:00
Max Romanov
7c4db34b88 Python: implementing input readline and line iterator. 2020-03-12 17:54:11 +03:00
Max Romanov
2454dfe876 Introducing readline function in libunit.
Ruby and Java modules now use this function instead of own
implementations.
2020-03-12 17:54:05 +03:00
Igor Sysoev
7935ea4543 Round robin upstream added. 2020-03-06 18:28:54 +03:00
Igor Sysoev
794248090a Legacy upstream code removed. 2020-03-04 14:04:08 +03:00
Igor Sysoev
643d4383fa Refactored nxt_http_action. 2020-03-04 14:03:32 +03:00
Axel Duch
f302ed0670 Fixed negative patterns combined with address rules. 2020-03-11 14:18:39 +00:00
Tiago Natel de Moura
36578c7b43 PHP: fixed log format in alert.
Found by Coverity: CID 354832 and CID 354833.
2020-03-04 13:42:08 +00:00
Igor Sysoev
2d0dca5243 The kqueue EOF flag might be ignored on some conditions.
If kqueue reported both the EVFILT_READ and the EVFILT_WRITE events
for the socket but only the former had the EV_EOF flag set, the flag
was silently ignored.
2020-03-04 14:03:30 +03:00
Valentin Bartenev
a98de7f705 Added a "fallback" option to be used with the "share" action.
It allows proceeding to another action if a file isn't available.

An example:

    {
        "share": "/data/www/",

        "fallback": {
            "pass": "applications/php"
        }
    }

In the example above, an attempt is made first to serve a request with
a file from the "/data/www/" directory.  If there's no such file, the
request is passed to the "php" application.

Fallback actions may be nested:

    {
        "share": "/data/www/",

        "fallback": {
            "share": "/data/cache/",

            "fallback": {
                "proxy": "http://127.0.0.1:9000"
            }
        }
    }
2020-03-03 20:37:47 +03:00
Valentin Bartenev
a60f856ce2 Improved validation of the "action" object.
Now it enforces the mutual exclusivity of "pass", "proxy", and "share" options.
2020-03-03 20:37:47 +03:00