From: Farrel Lifson Date: 2007-04-29T20:17:23+09:00 Subject: Strange DRb and fork issues ------=_Part_212249_10342094.1177845441000 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi all, I'm busy experimenting with DRb and I've hit some strange behaviour which I can't get seem to find the cause of. I think it might be something to do with DRb and forks but I'm unsure. The process I'm trying to achieve is to have a Server process running as a DRb service. It can spawn client processes (the create_client method) which also run using a DRb service. Upon spawning the clients create DRb proxy objects to the server and register using the register_client method passing through their client process pid and url. The server then creates DRb proxy objects with the information it receives and stores it in a hash with the client pid as the key. We can retrieve an array of client pid using the client_pids method on the server. I have encountered the following problem. When I start the server process and then start the client process independent from the server process everything seems to work fine. I can retrieve from the server the array of client pids and everything exits gracefully. However when I create the client from within the server process using the create_client method (like it hopefully would normally do) the server registers the client pid and stores it in the hash but on subsequent calls to get the array of pids it comes back empty(!) and a ruby process hangs around afterwards. I've attached some files showing this behaviour. Both tests in theory should be doing the same thing; registering a client with a server and then retrieving the array of client pids. farrel@nicodemus ~/Desktop $ ruby server.rb -n test_register_client Loaded suite server Started Registered client druby://localhost:41362, 1 clients registered . Finished in 0.310428 seconds. 1 tests, 1 assertions, 0 failures, 0 errors farrel@nicodemus ~/Desktop $ ps PID TTY TIME CMD 5404 pts/4 00:00:00 bash 5920 pts/4 00:00:00 ps farrel@nicodemus ~/Desktop $ ruby server.rb -n test_create_client Loaded suite server Started Registered client druby://localhost:2276, 1 clients registered F Finished in 0.315975 seconds. 1) Failure: test_create_client(TestServer) [server.rb:68]: <[5923]> expected but was <[]>. 1 tests, 1 assertions, 1 failures, 0 errors farrel@nicodemus ~/Desktop $ ps PID TTY TIME CMD 5404 pts/4 00:00:00 bash 5923 pts/4 00:00:00 ruby 5924 pts/4 00:00:00 ps As you can see the pid array comes back empty despite the server printing out the message that it has registered the client and for some reason there's a ruby process still hanging around. Any DRb experts out there who can help? Thanks Farrel ------=_Part_212249_10342094.1177845441000 Content-Type: application/octet-stream; name=base.rb Content-Transfer-Encoding: base64 X-Attachment-Id: f_f13ekyuv Content-Disposition: attachment; filename="base.rb" cmVxdWlyZSAnZHJiJwpjbGFzcyBCYXNlCiAgZGVmIEJhc2Uuc3RhcnQoKmFyZ3MpCiAgICBvYmpl Y3QgPSBzZWxmLm5ldygqYXJncykKICAgIERSYi5zdGFydF9zZXJ2aWNlKG9iamVjdC51cmwsb2Jq ZWN0KQogICAgRFJiLnRocmVhZC5qb2luCiAgZW5kCgogIGRlZiBpbml0aWFsaXplKGhvc3RuYW1l PW5pbCxwb3J0PW5pbCkKICAgIEBob3N0bmFtZSA9IGhvc3RuYW1lIHx8ICdsb2NhbGhvc3QnCiAg ICBAcG9ydCA9IHBvcnQgfHwgcmFuZCg2NDUxMSkrMTAyNCAgICAgCiAgZW5kCgogIGRlZiBleGl0 CiAgICBEUmIuc3RvcF9zZXJ2aWNlCiAgZW5kCgogIGRlZiB1cmwKICAgIHJldHVybiAiZHJ1Ynk6 Ly8je0Bob3N0bmFtZX06I3tAcG9ydH0iCiAgZW5kCmVuZAo= ------=_Part_212249_10342094.1177845441000 Content-Type: application/octet-stream; name=client.rb Content-Transfer-Encoding: base64 X-Attachment-Id: f_f13el4ty Content-Disposition: attachment; filename="client.rb" cmVxdWlyZSAnYmFzZScKCmNsYXNzIENsaWVudCA8IEJhc2UKICBkZWYgaW5pdGlhbGl6ZShob3N0 bmFtZSxwb3J0LHNlcnZlclVSTCkKICAgIHN1cGVyKGhvc3RuYW1lLHBvcnQpCiAgICBAc2VydmVy VVJMID0gc2VydmVyVVJMCiAgICBAc2VydmVyID0gRFJiOjpEUmJPYmplY3QubmV3KG5pbCxAc2Vy dmVyVVJMKQogICAgQHNlcnZlci5yZWdpc3Rlcl9jbGllbnQoUHJvY2Vzcy5waWQsc2VsZi51cmwp CiAgZW5kCmVuZAoK ------=_Part_212249_10342094.1177845441000 Content-Type: application/octet-stream; name=server.rb Content-Transfer-Encoding: base64 X-Attachment-Id: f_f13elp7q Content-Disposition: attachment; filename="server.rb" cmVxdWlyZSAndGVzdC91bml0JwpyZXF1aXJlICdiYXNlJwpyZXF1aXJlICdjbGllbnQnCgpjbGFz cyBTZXJ2ZXIgPCBCYXNlCiAgZGVmIGluaXRpYWxpemUoa2xhc3MsaG9zdG5hbWU9bmlsLHBvcnQ9 bmlsKQogICAgc3VwZXIoaG9zdG5hbWUscG9ydCkKICAgIEBrbGFzcyA9IGtsYXNzCiAgICBAY2xp ZW50cyA9IHt9CiAgZW5kCgogIGRlZiByZWdpc3Rlcl9jbGllbnQocGlkLHVybCkKICAgIEBjbGll bnRzW3BpZF0gPSB7OmRyYm9iamVjdCA9PiBEUmI6OkRSYk9iamVjdC5uZXcobmlsLHVybCksIDp1 cmwgPT4gdXJsfQogICAgcHV0cyAiUmVnaXN0ZXJlZCBjbGllbnQgI3t1cmx9LCAje0BjbGllbnRz LmtleXMuc2l6ZX0gY2xpZW50cyByZWdpc3RlcmVkIgogIGVuZAoKICBkZWYgY2xpZW50X3BpZHMK ICAgIEBjbGllbnRzLmtleXMKICBlbmQKCiAgZGVmIGV4aXRfY2xpZW50cwogICAgQGNsaWVudHMu dmFsdWVzLmVhY2ggZG8gfGNsaWVudEluZm98CiAgICAgIGNsaWVudEluZm9bOmRyYm9iamVjdF0u ZXhpdAogICAgZW5kCiAgZW5kCgogIGRlZiBjcmVhdGVfY2xpZW50KGhvc3RuYW1lPW5pbCxwb3J0 PW5pbCkgCiAgICBwaWQgPSBmb3JrIGRvCiAgICAgIEBrbGFzcy5zdGFydChob3N0bmFtZSxwb3J0 LHNlbGYudXJsKQogICAgZW5kCiAgICBQcm9jZXNzLmRldGFjaChwaWQpCiAgICBwaWQKICBlbmQK ZW5kCgpjbGFzcyBUZXN0U2VydmVyIDwgVGVzdDo6VW5pdDo6VGVzdENhc2UKICBkZWYgc2V0dXAK ICAgIHNyYW5kCiAgICBAc2VydmVySG9zdCA9ICdsb2NhbGhvc3QnCiAgICBAc2VydmVyUG9ydCA9 IHJ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