view · edit · sidebar · attach · print · history




  • port sbsm/ to use the rack webserver. Fix handling POST requests
  • Keep in Mind



port sbsm/ to use the rack webserver. Fix handling POST requests

Also the preserve the session, but cannot open the DrbConnection anymore. Why?

Looking at to generate class diagrams to more easily compare old and new sbsm versions.

Did not find a library that produces a nice dependency, that I could minimize to exctract the important classes.

Resuming the problem, after my changes I cannot find anymore the drb. With the currently pushed branches rack of sbsm I start in two session bundle exec bin/steinwies and bundle exec rackup. Then I visit http://localhost:8004 and with the help of pry I get

 bundle exec rackup
Passing app Steinwies::App
@app is NilClass sbsm-persistent-cookie-id Steinwies::App
/home/niklaus/git/sbsm/lib/sbsm/session.rb 300: logout @active_state now Steinwies::HomeState
[2016-10-31 10:10:05] INFO  WEBrick 1.3.1
[2016-10-31 10:10:05] INFO  ruby 2.3.1 (2016-04-26) [x86_64-linux]
[2016-10-31 10:10:05] INFO  WEBrick::HTTPServer#start: pid=4049 port=8004
found session #<Rack::Session::Abstract::SessionHash:0x000000025ccce8> @session_handler is_? Steinwies::Session

From: /home/niklaus/git/sbsm/lib/sbsm/app.rb @ line 114 SBSM::App#call:

    110:       session = Rack::Session::Abstract::SessionHash.find(@sbsm.request)
    111:       puts "found session #{session} @session_handler is_? #{@session_handler.class}"
    112:       @@counter += 1
    113:       require 'pry'; binding.pry if @@counter <= 3
 => 114:       response =
    115:       response = @sbsm.process(self, @session_handler, @server_uri)
    116:       response.set_cookie(COOKIE_ID, {:value => @sbsm.request.cookies[COOKIE_ID], :path => "/", :expires =>*60*60})
    117:       response.set_cookie('@@counter', {:value => @@counter, :path => "/", :expires =>*60*60})
    118:       response.set_cookie('saved_path', {:value => @sbsm.request.path, :path => "/", :expires =>*60*60})
    119:       response.set_cookie('saved_session', {:value => @session_handler, :path => "/", :expires =>*60*60})

[1] pry(#<Steinwies::AppWebrick>)> continue
@proxy is NilClass 

From: /home/niklaus/git/sbsm/lib/sbsm/request.rb @ line 213 SBSM::Request#drb_process:

    208:         if false
    209:           object =, app,
    210:           @proxy  =, @request.session[:proxy].server_uri.to_s) # worked
    211:         end
    212:         binding.pry
 => 213:         @proxy  =, server_uri)
    214:         require 'pry'; binding.pry unless @proxy.is_a?(DRb::DRbObject)
    215:         res1 = @proxy.drb_process(self)
    216:         res = @proxy.drb_process(self)
    217:       end
    218:       html = @response.write(res)

[1] pry(#<SBSM::Request>)> continue
DRb::DRbServerNotFound: DRb::DRbServerNotFound
        /usr/local/lib/ruby/2.3.0/drb/drb.rb:1718:in `current_server'
        /usr/local/lib/ruby/2.3.0/drb/drb.rb:1787:in `to_id'
        /usr/local/lib/ruby/2.3.0/drb/drb.rb:1103:in `initialize'
        /home/niklaus/git/sbsm/lib/sbsm/request.rb:213:in `new'
        /home/niklaus/git/sbsm/lib/sbsm/request.rb:213:in `drb_process'
        /home/niklaus/git/sbsm/lib/sbsm/request.rb:100:in `process'
        /home/niklaus/git/sbsm/lib/sbsm/app.rb:115:in `call'
        /home/niklaus/git/ `_call'
        /home/niklaus/git/ `call'
        /home/niklaus/git/ `call'
        /home/niklaus/git/ `context'
        /home/niklaus/git/ `call'
        /home/niklaus/git/ `service'
        /usr/local/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service'
        /usr/local/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run'
        /usr/local/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread'
::1 - - [31/Oct/2016:10:10:26 CET] "GET / HTTP/1.1" 500 55417
- -> /

The local variable server_uri is correct #<URI::Generic druby://localhost:10001>.

Zeno pointed me to, which seems to have solved a very similar problem. Must analys what the Rack::RewindableInput is and how the CGIHandler in the above example works.

I think it might be a good idea to test steinwies/sbsm by creating a test, where we increment the counter in the remote DRbServer. This might be also part of the missing test-app for completing the SBSM unit tests.

Reading which gives some explanation of the differences between CGI (as done via mod_ruby) and the Rack/Webrick approach. But shouldn't we get rid of the CGI completely? But how?

I think I can safely remove the file lib/cgi/drb_session.rb as it not used anywhere.

Started working on, which should be a very simply example. It will increment a counter and display the requested path (may be later on also the cookie).

Created, bin/simple and src/util/simple_app.rb. Now bin/simple and rackup, but I do not see yet a call into the Drb-Process launched by bin/simple. This was expected. Pushed commit Added simple-app to test for DRb. Cookies/DRb not recognized

Now first adding preserving of session, then connecting to the DrbProcess. Done with commit Simple example with a working DRb and session.

Now the whole class structure is quite different. The DRbServer only works because it is no longer derived from the simple delegator. Is this a disadvantage? Or was it derived to avoid memory leaks present in Ruby and its classes around 2005 when the gem was developed?

When looking at the output bin/simple I can easily trace the two sesssion (one from chromium, the other one with firefox), where I visited a few place:

bundle exec bin/simple 
Starting druby://localhost:18999
simple_app.rb:55 process #<Rack::Request:0x00000002a37d50> path: /test6799 id: 0.9403210530719527
simple_app.rb:55 process #<Rack::Request:0x000000029e5f00> path: /new38 id: 
simple_app.rb:55 process #<Rack::Request:0x0000000278d708> path: /new399 id: 0.117203343869001
simple_app.rb:55 process #<Rack::Request:0x000000026ca848> path: /new400 id: 0.117203343869001
simple_app.rb:55 process #<Rack::Request:0x0000000262b5b8> path: /test6 id: 0.9403210530719527

The output of rackup show the few parts I passed through my code

 bundle exec rackup 
simple_app.rb:194 initialize @app is now #<Simple:0x00000002b05548 @sessions={}, @system=nil>
[2016-10-31 15:21:28] INFO  WEBrick 1.3.1
[2016-10-31 15:21:28] INFO  ruby 2.3.1 (2016-04-26) [x86_64-linux]
[2016-10-31 15:21:28] INFO  WEBrick::HTTPServer#start: pid=30019 port=8888
simple_app.rb:199 cookies are {"sbsm-persistent-cookie"=>"", "sbsm-persistent-cookie-id"=>"0.9403210530719527", "@@counter"=>"4", "old_path"=>"/test6799", "_session_id"=>""}
simple_app.rb:202 _session_id is 0.9403210530719527 or nil
simple_app.rb:208 found session #<Rack::Session::Abstract::SessionHash:0x00000002a4c750> @session_handler is_? NilClass
result is "simple_app.rb:55 process #<Rack::Request:0x00000002a37d50> path: /test6799 id: 0.9403210530719527" session_id 0.9403210530719527
::1 - - [31/Oct/2016:15:21:32 CET] "GET /test6799 HTTP/1.1" 200 0
- -> /test6799

Remove the Rack::Session::Pool, which I think we do not need at the moment with commit Got rid of Rack::Session::Pool

Made the display nicer and verifying that we really use DRb to access a different linux process. Now the output of http://localhost:8888/test810 looks like this

simple_app.rb:55 DRbPid 19306
request: #<Rack::Request:0x000000021b7c20> path: /test810 id: 0.9403210530719527
Passthrough (WebRick PID) is 20135
@@counter is 4
session_id is 0.9403210530719527

Now removing the simple implementations for SBSM in simple_app.rb and replacing it with (possibly modified) classes from SBSM. Now I am beginning to understand. I must find the used session via a call to @app[session_id] and calling process for the returned session. Now my simple_app complains, because no validator is given.

Adaptation continued. Now I am asking myself about how the DRbObjects are handled in the procedure call(env)

      puts "result is #{result.inspect} session_id #{session_id}"
      puts DRbObject.new_with_uri(SERVER_URI).to_s
      puts session.to_s
      # @proxy = DRbObject.new_with_uri(SERVER_URI)
      @proxy =, SERVER_URI)
      puts @proxy.to_s
      session.drb_process self # das läuft
      res = @proxy.drb_process(self) # das nicht
results in the following output
result is "" session_id 0.831724324438134 WebRick has pid 4602
simple_app.rb:83 Im the Steinwies DrbServer from the pid 4519
simple_app.rb:83 Im the Steinwies DrbServer from the pid 4602
simple_app.rb:83 Im the Steinwies DrbServer from the pid 4602
RangeError: 0x00000001521038 is not id value
        (druby://localhost:18999) /usr/local/lib/ruby/2.3.0/drb/drb.rb:373:in `_id2ref'
        (druby://localhost:18999) /usr/local/lib/ruby/2.3.0/drb/drb.rb:373:in `to_obj'
        (druby://localhost:18999) /usr/local/lib/ruby/2.3.0/drb/drb.rb:1483:in `to_obj'
        (druby://localhost:18999) /usr/local/lib/ruby/2.3.0/drb/drb.rb:1779:in `to_obj'
        (druby://localhost:18999) /usr/local/lib/ruby/2.3.0/drb/drb.rb:622:in `recv_request'
        (druby://localhost:18999) /usr/local/lib/ruby/2.3.0/drb/drb.rb:931:in `recv_request'
        (druby://localhost:18999) /usr/local/lib/ruby/2.3.0/drb/drb.rb:1599:in `init_with_client'
        (druby://localhost:18999) /usr/local/lib/ruby/2.3.0/drb/drb.rb:1611:in `setup_message'
        (druby://localhost:18999) /usr/local/lib/ruby/2.3.0/drb/drb.rb:1563:in `perform'
        (druby://localhost:18999) /usr/local/lib/ruby/2.3.0/drb/drb.rb:1657:in `block (2 levels) in main_loop'
        (druby://localhost:18999) /usr/local/lib/ruby/2.3.0/drb/drb.rb:1653:in `loop'
        (druby://localhost:18999) /usr/local/lib/ruby/2.3.0/drb/drb.rb:1653:in `block in main_loop'
        /home/niklaus/git/ `call'
        /home/niklaus/git/ `_call'
        /home/niklaus/git/ `call'
        /home/niklaus/git/ `call'
        /home/niklaus/git/ `service'
        /usr/local/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service'
        /usr/local/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run'
        /usr/local/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread'

In my previous stub implementation of SBSM::DrbServer I had removed the inheritance from SimpleDelegator and my code worked. Now I readded it again and I am still getting the same error. Pushing my changes for steinwies and sbsm.

Pushed the following commits:

view · edit · sidebar · attach · print · history
Page last modified on October 31, 2016, at 06:26 PM