<feed xmlns='http://www.w3.org/2005/Atom'>
<title>unit.git/src/ruby, branch 1.35.0</title>
<subtitle>Universal Web Application Server</subtitle>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/'/>
<entry>
<title>Set SERVER_PORT appropriately</title>
<updated>2025-07-25T03:49:45+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>a.clayton@nginx.com</email>
</author>
<published>2025-07-04T15:38:25+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=c8b859e373089d3f347efb806c9926823de41bf6'/>
<id>c8b859e373089d3f347efb806c9926823de41bf6</id>
<content type='text'>
The Perl, PHP, Python, Ruby &amp; Java language modules all hard code
SERVER_PORT to "80".

Adjust them to bring them in line with the wasm language module which
uses r-&gt;local_port (I.e. the port unit accepted the connection on).

Closes: https://github.com/nginx/unit/issues/761
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The Perl, PHP, Python, Ruby &amp; Java language modules all hard code
SERVER_PORT to "80".

Adjust them to bring them in line with the wasm language module which
uses r-&gt;local_port (I.e. the port unit accepted the connection on).

Closes: https://github.com/nginx/unit/issues/761
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Use NULL instead of 0 as null pointer constant</title>
<updated>2025-05-28T15:35:34+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>a.clayton@nginx.com</email>
</author>
<published>2025-05-21T03:13:11+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=39f9121339559738cba5130c818e8920e1a2fa16'/>
<id>39f9121339559738cba5130c818e8920e1a2fa16</id>
<content type='text'>
GCC 15 enabled "-Wzero-as-null-pointer-constant" for C, which checks for
places where '0' has been used as a null pointer constant.

This showed a few places in Unit where we were using '0' instead of the
more correct NULL macro. E.g.

  $ make -j4 EXTRA_CFLAGS=-Wzero-as-null-pointer-constant
  ...
  src/nxt_buf.c: In function ‘nxt_buf_mmap_alloc’:
  src/nxt_buf.h:192:21: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant]
    192 |         (bm)-&gt;start = 0;                                                      \
        |                     ^
  src/nxt_buf.c:135:9: note: in expansion of macro ‘nxt_buf_mem_set_size’
    135 |         nxt_buf_mem_set_size(&amp;b-&gt;mem, size);
        |         ^~~~~~~~~~~~~~~~~~~~

Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
GCC 15 enabled "-Wzero-as-null-pointer-constant" for C, which checks for
places where '0' has been used as a null pointer constant.

This showed a few places in Unit where we were using '0' instead of the
more correct NULL macro. E.g.

  $ make -j4 EXTRA_CFLAGS=-Wzero-as-null-pointer-constant
  ...
  src/nxt_buf.c: In function ‘nxt_buf_mmap_alloc’:
  src/nxt_buf.h:192:21: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant]
    192 |         (bm)-&gt;start = 0;                                                      \
        |                     ^
  src/nxt_buf.c:135:9: note: in expansion of macro ‘nxt_buf_mem_set_size’
    135 |         nxt_buf_mem_set_size(&amp;b-&gt;mem, size);
        |         ^~~~~~~~~~~~~~~~~~~~

Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>ruby: Fix build failures with Ruby 3.4</title>
<updated>2025-01-22T21:57:56+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>a.clayton@nginx.com</email>
</author>
<published>2025-01-21T19:15:02+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=7b7b29fcfe077e577cf088414cff0128bfb0c1bf'/>
<id>7b7b29fcfe077e577cf088414cff0128bfb0c1bf</id>
<content type='text'>
Ruby 3.4 started to actually mark some deprecated functions as
*deprecated* now resulting in compiler warnings (which due to -Werror we
treat as errors and thus the build fails).

The *new* functions were actually introduced back in Ruby 1.9.2, so have
been around for quite some time. We claim support for Ruby 2.0 onwards
so this is more than fine.

The new API replaces the old 'mark' and 'free' parameters with a struct
that allows for more fine tuning/configuration. We never made use of
either of those parameters and so the only members of this struct we
*need* to set is the structure wrapper name and the dsize function
pointer which is passed a pointer to the underlying wrapped structure to
calculate its memory usage. While this is *not* required the
documentation *recommends* setting it (though it doesn't say how it's
used).

Ruby pytests still pass after this change...

Closes: https://github.com/nginx/unit/issues/1525
Link: &lt;https://bugs.ruby-lang.org/issues/19998&gt;
Link: &lt;https://docs.ruby-lang.org/en/3.4/extension_rdoc.html#label-C+struct+to+Ruby+object&gt;
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Ruby 3.4 started to actually mark some deprecated functions as
*deprecated* now resulting in compiler warnings (which due to -Werror we
treat as errors and thus the build fails).

The *new* functions were actually introduced back in Ruby 1.9.2, so have
been around for quite some time. We claim support for Ruby 2.0 onwards
so this is more than fine.

The new API replaces the old 'mark' and 'free' parameters with a struct
that allows for more fine tuning/configuration. We never made use of
either of those parameters and so the only members of this struct we
*need* to set is the structure wrapper name and the dsize function
pointer which is passed a pointer to the underlying wrapped structure to
calculate its memory usage. While this is *not* required the
documentation *recommends* setting it (though it doesn't say how it's
used).

Ruby pytests still pass after this change...

Closes: https://github.com/nginx/unit/issues/1525
Link: &lt;https://bugs.ruby-lang.org/issues/19998&gt;
Link: &lt;https://docs.ruby-lang.org/en/3.4/extension_rdoc.html#label-C+struct+to+Ruby+object&gt;
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Ruby: Prevent a possible integer underflow</title>
<updated>2023-12-13T03:20:25+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>a.clayton@nginx.com</email>
</author>
<published>2023-12-13T02:04:38+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=88854cf14688286f835f7177c6bfaa17f1962f67'/>
<id>88854cf14688286f835f7177c6bfaa17f1962f67</id>
<content type='text'>
Coverity picked up a potential issue with the previous commit d9f5f1fb7
("Ruby: Handle response field arrays") in that a size_t could wrap
around to SIZE_MAX - 1.

This would happen if we were given an empty array of header values.

Fixes: d9f5f1fb7 ("Ruby: Handle response field arrays")
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Coverity picked up a potential issue with the previous commit d9f5f1fb7
("Ruby: Handle response field arrays") in that a size_t could wrap
around to SIZE_MAX - 1.

This would happen if we were given an empty array of header values.

Fixes: d9f5f1fb7 ("Ruby: Handle response field arrays")
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Ruby: Handle response field arrays</title>
<updated>2023-12-08T13:48:33+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>a.clayton@nginx.com</email>
</author>
<published>2023-10-23T13:24:01+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=d9f5f1fb741109cc232cedd3574aa587626789c1'/>
<id>d9f5f1fb741109cc232cedd3574aa587626789c1</id>
<content type='text'>
@xeron on GitHub reported an issue whereby with a Rails 7.1 application
they were getting the following error

  2023/10/22 20:57:28 [error] 56#56 [unit] #8: Ruby: Wrong header entry 'value' from application
  2023/10/22 20:57:28 [error] 56#56 [unit] #8: Ruby: Failed to run ruby script

After some back and forth debugging it turns out rack was trying to send
back a header comprised of an array of values. E.g

  app = Proc.new do |env|
      ["200", {
          "Content-Type" =&gt; "text/plain",
          "X-Array-Header" =&gt; ["Item-1", "Item-2"],
      }, ["Hello World\n"]]
  end

  run app

It seems this became a possibility in rack v3.0[0]

So along with a header value type of T_STRING we need to also allow
T_ARRAY.

If we get a T_ARRAY we need to build up the header field using the given
values.

E.g

  "X-Array-Header" =&gt; ["Item-1", "", "Item-3", "Item-4"],

becomes

  X-Array-Header: Item-1; ; Item-3; Item-4

[0]: &lt;https://github.com/rack/rack/blob/main/UPGRADE-GUIDE.md?plain=1#L26&gt;

Reported-by: Ivan Larionov &lt;xeron.oskom@gmail.com&gt;
Closes: &lt;https://github.com/nginx/unit/issues/974&gt;
Link: &lt;https://github.com/nginx/unit/pull/998&gt;
Tested-by: Timo Stark &lt;t.stark@nginx.com&gt;
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
@xeron on GitHub reported an issue whereby with a Rails 7.1 application
they were getting the following error

  2023/10/22 20:57:28 [error] 56#56 [unit] #8: Ruby: Wrong header entry 'value' from application
  2023/10/22 20:57:28 [error] 56#56 [unit] #8: Ruby: Failed to run ruby script

After some back and forth debugging it turns out rack was trying to send
back a header comprised of an array of values. E.g

  app = Proc.new do |env|
      ["200", {
          "Content-Type" =&gt; "text/plain",
          "X-Array-Header" =&gt; ["Item-1", "Item-2"],
      }, ["Hello World\n"]]
  end

  run app

It seems this became a possibility in rack v3.0[0]

So along with a header value type of T_STRING we need to also allow
T_ARRAY.

If we get a T_ARRAY we need to build up the header field using the given
values.

E.g

  "X-Array-Header" =&gt; ["Item-1", "", "Item-3", "Item-4"],

becomes

  X-Array-Header: Item-1; ; Item-3; Item-4

[0]: &lt;https://github.com/rack/rack/blob/main/UPGRADE-GUIDE.md?plain=1#L26&gt;

Reported-by: Ivan Larionov &lt;xeron.oskom@gmail.com&gt;
Closes: &lt;https://github.com/nginx/unit/issues/974&gt;
Link: &lt;https://github.com/nginx/unit/pull/998&gt;
Tested-by: Timo Stark &lt;t.stark@nginx.com&gt;
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Ruby: used nxt_ruby_exception_log() in nxt_ruby_rack_init().</title>
<updated>2022-10-04T18:33:11+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>a.clayton@nginx.com</email>
</author>
<published>2022-10-03T12:01:33+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=d806a90609e99cb4c8db71d620d5db3d26e83693'/>
<id>d806a90609e99cb4c8db71d620d5db3d26e83693</id>
<content type='text'>
For consistency use nxt_ruby_exception_log() rather than nxt_alert() in
nxt_ruby_rack_init().

Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
For consistency use nxt_ruby_exception_log() rather than nxt_alert() in
nxt_ruby_rack_init().

Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Ruby: added support for rack V3.</title>
<updated>2022-10-04T18:33:11+00:00</updated>
<author>
<name>Zhidao HONG</name>
<email>z.hong@f5.com</email>
</author>
<published>2022-09-28T14:51:55+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=dc9f592d6e7123d57924146dcbf1be80366bc98b'/>
<id>dc9f592d6e7123d57924146dcbf1be80366bc98b</id>
<content type='text'>
Ruby applications would fail to start if they were using rack v3

  2022/09/28 15:48:46 [alert] 0#80912 [unit] Ruby: Failed to parse rack script
  2022/09/28 15:48:46 [notice] 80911#80911 app process 80912 exited with code 1

This was due to a change in the rack API

Rack V2

  def self.load_file(path, opts = Server::Options.new)
    ...
    cfgfile.sub!(/^__END__\n.*\Z/m, '')
    app = new_from_string cfgfile, path

    return app, options
  end

Rack V3

  def self.load_file(path)
    ...

    return new_from_string(config, path)
  end

This patch handles _both_ the above APIs by correctly handling the cases
where we do and don't get an array returned from
nxt_ruby_rack_parse_script().

Closes: &lt;https://github.com/nginx/unit/issues/755&gt;
Tested-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
Reviewed-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
[ Andrew: Patch by Zhidao, commit message by me with input from Zhidao ]
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Ruby applications would fail to start if they were using rack v3

  2022/09/28 15:48:46 [alert] 0#80912 [unit] Ruby: Failed to parse rack script
  2022/09/28 15:48:46 [notice] 80911#80911 app process 80912 exited with code 1

This was due to a change in the rack API

Rack V2

  def self.load_file(path, opts = Server::Options.new)
    ...
    cfgfile.sub!(/^__END__\n.*\Z/m, '')
    app = new_from_string cfgfile, path

    return app, options
  end

Rack V3

  def self.load_file(path)
    ...

    return new_from_string(config, path)
  end

This patch handles _both_ the above APIs by correctly handling the cases
where we do and don't get an array returned from
nxt_ruby_rack_parse_script().

Closes: &lt;https://github.com/nginx/unit/issues/755&gt;
Tested-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
Reviewed-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
[ Andrew: Patch by Zhidao, commit message by me with input from Zhidao ]
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Renamed a couple of members of nxt_unit_request_t.</title>
<updated>2022-10-03T13:32:28+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>a.clayton@nginx.com</email>
</author>
<published>2022-09-29T19:59:43+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=b00983369be5f356280168b4c5d600bd7d614c60'/>
<id>b00983369be5f356280168b4c5d600bd7d614c60</id>
<content type='text'>
This is a preparatory patch that renames the 'local' and 'local_length'
members of the nxt_unit_request_t structure to 'local_addr' and
'local_addr_length' in preparation for the adding of 'local_port' and
'local_port_length' members.

Suggested-by: Zhidao HONG &lt;z.hong@f5.com&gt;
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This is a preparatory patch that renames the 'local' and 'local_length'
members of the nxt_unit_request_t structure to 'local_addr' and
'local_addr_length' in preparation for the adding of 'local_port' and
'local_port_length' members.

Suggested-by: Zhidao HONG &lt;z.hong@f5.com&gt;
Signed-off-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Ruby: prevented a segfault on receiving SIGINT (^C).</title>
<updated>2022-08-31T12:17:02+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>a.clayton@f5.com</email>
</author>
<published>2022-08-31T11:49:15+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=b26624fc10cc1f4eb88c16ac8fb5b6b4b61895fc'/>
<id>b26624fc10cc1f4eb88c16ac8fb5b6b4b61895fc</id>
<content type='text'>
As was reported[0] by @travisbell on GitHub, if running unit from the
terminal in the foreground when hitting ^C to exit it, the ruby
application processes would segfault if they were using threads.

It's not 100% clear where the actual problem lies, but it _looks_ like
it may be in ruby.

The simplest way to deal with this for now is to just ignore SIGINT in
the ruby application processes. Unit will still receive and handle it,
cleanly shutting everything down.

For people who want to handle SIGINT in their ruby application running
under unit they can still trap SIGINT and it will override the ignore.

[0]: https://github.com/nginx/unit/issues/562#issuecomment-1223229585

Closes: https://github.com/nginx/unit/issues/562
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
As was reported[0] by @travisbell on GitHub, if running unit from the
terminal in the foreground when hitting ^C to exit it, the ruby
application processes would segfault if they were using threads.

It's not 100% clear where the actual problem lies, but it _looks_ like
it may be in ruby.

The simplest way to deal with this for now is to just ignore SIGINT in
the ruby application processes. Unit will still receive and handle it,
cleanly shutting everything down.

For people who want to handle SIGINT in their ruby application running
under unit they can still trap SIGINT and it will override the ignore.

[0]: https://github.com/nginx/unit/issues/562#issuecomment-1223229585

Closes: https://github.com/nginx/unit/issues/562
</pre>
</div>
</content>
</entry>
<entry>
<title>Ruby: fixed segfault on SIGTERM signal.</title>
<updated>2022-07-28T03:00:15+00:00</updated>
<author>
<name>Zhidao HONG</name>
<email>z.hong@f5.com</email>
</author>
<published>2022-07-28T03:00:15+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=2bd4a455278dbce756c1dc8be07515f73d611e3b'/>
<id>2bd4a455278dbce756c1dc8be07515f73d611e3b</id>
<content type='text'>
This closes #562 issue on GitHub.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This closes #562 issue on GitHub.
</pre>
</div>
</content>
</entry>
</feed>
