Code Monkey home page Code Monkey logo

Comments (11)

DomasM avatar DomasM commented on June 13, 2024 1

from vernemq.

ioolkos avatar ioolkos commented on June 13, 2024

@DomasM Thanks. Can you try setting max_request_line_length in vernemq.conf?

listener.tcp.default.max_request_line_length=16500 (whatever length you might seem to need)
Set this for your named listener where you'll need it. (adapt default to your listener name)


👉 Thank you for supporting VerneMQ: https://github.com/sponsors/vernemq
👉 Using the binary VerneMQ packages commercially (.deb/.rpm/Docker) requires a paid subscription.

from vernemq.

DomasM avatar DomasM commented on June 13, 2024

@ioolkos Thank you for help. I'm not sure what's my listener name, but anyway vernemq would not start with such setting, saying that it does not exist and suggesting listener.http.default.max_request_line_length, which I tried but it seems that did not change anything in actual behaviour, i.e. still 431.

vernemq  | 2024-03-15T11:42:36.795012+00:00 [error] You've tried to set listener.tcp.default.max_request_line_length, but there is no setting with that name.
vernemq  | 2024-03-15T11:42:36.795098+00:00 [error] Did you mean one of these?
vernemq  | 2024-03-15T11:42:36.891103+00:00 [error] listener.http.$name.max_request_line_length
vernemq  | 2024-03-15T11:42:36.891199+00:00 [error] listener.https.$name.max_request_line_length
vernemq  | 2024-03-15T11:42:36.891270+00:00 [error] listener.tcp.$name.max_connection_lifetime
vernemq  | 2024-03-15T11:42:36.893026+00:00 [error] Error generating configuration in phase transform_datatypes
vernemq  | 2024-03-15T11:42:36.893124+00:00 [error] Conf file attempted to set unknown variable: listener.tcp.default.max_request_line_length
vernemq exited with code 0

from vernemq.

ioolkos avatar ioolkos commented on June 13, 2024

@DomasM Thanks a lot for testing!
The config is obviously only for HTTP listeners, sorry about that.
There's additional options for Cowboy/Ranch connections:
https://github.com/ninenines/cowboy/blob/3ea8395eb8f53a57acb5d3c00b99c70296e7cdbd/doc/src/manual/cowboy_http.asciidoc#L31
Those are currently not exposed in the vernemq.conf file like max_request_line_length.

A workaround is to update the max_header_value_length option dynamically in a VerneMQ shell. (sudo vernemq attach, when done detach with ctrl+g and then at the user switch q).
Example for a HTTP listener running on 127.0.0.1:8888. The listener does not have to be restarted, it is updated live:

Opts = ranch:get_protocol_options({{127,0,0,1}, 8888}).
NewOpts = maps:put(max_header_value_length, 8192, Opts).
ranch:set_protocol_options({{127,0,0,1}, 8888}, NewOpts).

You could at least use this to test whether this really is about that specific setting. The default value for max_header_value_length is 4096.


👉 Thank you for supporting VerneMQ: https://github.com/sponsors/vernemq
👉 Using the binary VerneMQ packages commercially (.deb/.rpm/Docker) requires a paid subscription.

from vernemq.

DomasM avatar DomasM commented on June 13, 2024

@ioolkos Thank you again. I tried as suggested and while setting cowboy options seems to work, further requests still end with 431.
Additionally, as you can see initial max_header_value_length is 8192, while my cookie size is about 6700, so it should still pass?
https://github.com/ninenines/cowboy/blob/3ea8395eb8f53a57acb5d3c00b99c70296e7cdbd/src/cowboy_http.erl#L677

Opts = ranch:get_protocol_options({{127,0,0,1}, 8888}).
#{connection_type => supervisor,
  env =>
      #{dispatch =>
            [{'_',[],
                  [{[<<"metrics">>],[],vmq_metrics_http,[]},
                   {[<<"api">>,<<"v1">>,'...'],[],vmq_http_mgmt_api,[]},
                   {[<<"status.json">>],[],vmq_status_http,[]},
                   {[<<"status">>],
                    [],cowboy_static,
                    {priv_file,vmq_server,"static/index.html"}},
                   {[<<"status">>,'...'],
                    [],cowboy_static,
                    {priv_dir,vmq_server,"static"}},
                   {[<<"health">>],[],vmq_health_http,[]},
                   {[<<"api">>,<<"v2">>,command],[],vmq_http_v2_api,[]},
                   {[<<"restmqtt">>,<<"api">>,<<"v1">>,<<"publish">>],
                    [],vmq_http_pub,
                    [{publish_fun,#Fun<vmq_reg.17.40855500>}]}]}]},
  max_header_value_length => 8192,
  opts =>
      [{max_connections,10000},
       {nr_of_acceptors,10},
       {config_mod,vmq_http_config},
       {config_fun,config},
       {max_request_line_length,63000},
       {http_modules,"[]"},
       {listener_name,"default"},
       {proxy_protocol,false}]}
([email protected])2> NewOpts = maps:put(max_header_value_length, 62999, Opts).
#{connection_type => supervisor,
  env =>
      #{dispatch =>
            [{'_',[],
                  [{[<<"metrics">>],[],vmq_metrics_http,[]},
                   {[<<"api">>,<<"v1">>,'...'],[],vmq_http_mgmt_api,[]},
                   {[<<"status.json">>],[],vmq_status_http,[]},
                   {[<<"status">>],
                    [],cowboy_static,
                    {priv_file,vmq_server,"static/index.html"}},
                   {[<<"status">>,'...'],
                    [],cowboy_static,
                    {priv_dir,vmq_server,"static"}},
                   {[<<"health">>],[],vmq_health_http,[]},
                   {[<<"api">>,<<"v2">>,command],[],vmq_http_v2_api,[]},
                   {[<<"restmqtt">>,<<"api">>,<<"v1">>,<<"publish">>],
                    [],vmq_http_pub,
                    [{publish_fun,#Fun<vmq_reg.17.40855500>}]}]}]},
  max_header_value_length => 62999,
  opts =>
      [{max_connections,10000},
       {nr_of_acceptors,10},
       {config_mod,vmq_http_config},
       {config_fun,config},
       {max_request_line_length,63000},
       {http_modules,"[]"},
       {listener_name,"default"},
       {proxy_protocol,false}]}
([email protected])3> ranch:set_protocol_options({{127,0,0,1}, 8888}, NewOpts).
ok
Opts2 = ranch:get_protocol_options({{127,0,0,1}, 8888}).
#{connection_type => supervisor,
  env =>
      #{dispatch =>
            [{'_',[],
                  [{[<<"metrics">>],[],vmq_metrics_http,[]},
                   {[<<"api">>,<<"v1">>,'...'],[],vmq_http_mgmt_api,[]},
                   {[<<"status.json">>],[],vmq_status_http,[]},
                   {[<<"status">>],
                    [],cowboy_static,
                    {priv_file,vmq_server,"static/index.html"}},
                   {[<<"status">>,'...'],
                    [],cowboy_static,
                    {priv_dir,vmq_server,"static"}},
                   {[<<"health">>],[],vmq_health_http,[]},
                   {[<<"api">>,<<"v2">>,command],[],vmq_http_v2_api,[]},
                   {[<<"restmqtt">>,<<"api">>,<<"v1">>,<<"publish">>],
                    [],vmq_http_pub,
                    [{publish_fun,#Fun<vmq_reg.17.40855500>}]}]}]},
  max_header_value_length => 62999,
  opts =>
      [{max_connections,10000},
       {nr_of_acceptors,10},
       {config_mod,vmq_http_config},
       {config_fun,config},
       {max_request_line_length,63000},
       {http_modules,"[]"},
       {listener_name,"default"},
       {proxy_protocol,false}]}

from vernemq.

ioolkos avatar ioolkos commented on June 13, 2024

Hm, okay. What listeners do you have running (vmq-admin listener show), and is port 8888 really where you have that listener running?


👉 Thank you for supporting VerneMQ: https://github.com/sponsors/vernemq
👉 Using the binary VerneMQ packages commercially (.deb/.rpm/Docker) requires a paid subscription.

from vernemq.

DomasM avatar DomasM commented on June 13, 2024

I suppose. Tried setting cowboy options for 8080, but it complained.

Opts = ranch:get_protocol_options({{127,0,0,1}, 8080}).
** exception error: bad argument
     in function  ets:lookup_element/3
        called as ets:lookup_element(ranch_server,{proto_opts,{{127,0,0,1},8080}},2)
        *** argument 2: not a key that exists in the table
     in call from ranch_server:get_protocol_options/1 (/opt/vernemq/_build/default/lib/ranch/src/ranch_server.erl, line 168)
$ vmq-admin listener show
+--------+---------+--------------+-------+------------+-----------+--------------+-----------+
| type   | status  | address      | port  | mountpoint | max_conns | active_conns | all_conns |
+--------+---------+--------------+-------+------------+-----------+--------------+-----------+
| http   | running | 127.0.0.1    | 8888  |            | 10000     | 0            | 0         |
+--------+---------+--------------+-------+------------+-----------+--------------+-----------+
| mqtt   | running | 192.168.16.2 | 1883  |            | 10000     | 4            | 4         |
+--------+---------+--------------+-------+------------+-----------+--------------+-----------+
| mqttws | running | 192.168.16.2 | 8080  |            | 10000     | 0            | 0         |
+--------+---------+--------------+-------+------------+-----------+--------------+-----------+
| http   | running | 192.168.16.2 | 8888  |            | 10000     | 0            | 0         |
+--------+---------+--------------+-------+------------+-----------+--------------+-----------+
| vmq    | running | 192.168.16.2 | 44053 |            | 10000     | 0            | 0         |
+--------+---------+--------------+-------+------------+-----------+--------------+-----------+

from vernemq.

ioolkos avatar ioolkos commented on June 13, 2024

You don't have a listener {{127,0,0,1}, 8080}, you have {{192,168,16,2}, 8080}.


👉 Thank you for supporting VerneMQ: https://github.com/sponsors/vernemq
👉 Using the binary VerneMQ packages commercially (.deb/.rpm/Docker) requires a paid subscription.

from vernemq.

ioolkos avatar ioolkos commented on June 13, 2024

@DomasM were you able to make this work?

Do you think we should expose the max_header_value_length in vernemq.conf? or to re-word the question: do you think the cookie size you used here should be within a "normal" size window?


👉 Thank you for supporting VerneMQ: https://github.com/sponsors/vernemq
👉 Using the binary VerneMQ packages commercially (.deb/.rpm/Docker) requires a paid subscription.

from vernemq.

DomasM avatar DomasM commented on June 13, 2024

@ioolkos I finally got it working by setting max_header_value_length for the correct listener. IP address of the listener changes from run to run, so the steps current solution is:

  1. Modify vernemq.conf file with listener.http.default.max_request_line_length=63000
  2. Run vernemq
  3. Run vmq-admin listener show and notice which ip address and port is used for mqttws listener
  4. Set options for cowboy/ranch with these IP address and port values.
Address = {192,168,32,2}.
Port = 8080.
Opts = ranch:get_protocol_options({Address, Port}).
NewOpts = maps:put(max_header_value_length, 62999, Opts).
ranch:set_protocol_options({Address, Port}, NewOpts).

To have this working more properly maybe some copy-paste from #2161 would be enough to map max_header_value_length property too?

from vernemq.

ioolkos avatar ioolkos commented on June 13, 2024

@DomasM yes, same approach. In addition, we'd likely need to grab and apply the setting in vmq_ranch_config module where we set the protocol_opts.


👉 Thank you for supporting VerneMQ: https://github.com/sponsors/vernemq
👉 Using the binary VerneMQ packages commercially (.deb/.rpm/Docker) requires a paid subscription.

from vernemq.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.