rtomayko / posix-spawn

Ruby process spawning library
Other
519 stars 52 forks source link

strange failure on rubinius #5

Closed tmm1 closed 13 years ago

tmm1 commented 13 years ago

I fixed compilation issues and a couple other test failures against the latest rbx release, but couldn't figure out what's causing this failure:

Started
....................................................................................hiya
F.................
Finished in 5.119071 seconds.

  1) Failure:
test_spawn_redirect_invalid_fds_raises_exception(PosixSpawnTest)
    [./test/test_spawn.rb:332:in `assert_process_exit_status'
     ./test/test_spawn.rb:159:in `test_spawn_redirect_invalid_fds_raises_exception'
     kernel/bootstrap/array.rb:76:in `each'
     kernel/bootstrap/array.rb:76:in `each']:
<127> expected but was
<0>.

102 tests, 316 assertions, 1 failures, 0 errors
tmm1 commented 13 years ago

The failing test in question is

def test_spawn_close_invalid_fd_raises_exception
  pid = _spawn("echo", "hiya", 250 => :close)
  assert_process_exit_status pid, 127
rescue Errno::EBADF
  # this happens on darwin only. GNU does spawn and exits 127.
end

and it only fails when using the POSIX::Spawn.pspawn. For some reason, posix_spawn_file_actions_addclose(fops, 250) does not fail.

@evanphx any ideas? is it possible 250 is a valid file descriptor on rbx for some reason?

tmm1 commented 13 years ago

Wow I completely screwed that up. The actual failure is in redirect_invalid_fd, not close_invalid_fd. The code is

def test_spawn_redirect_invalid_fds_raises_exception
  pid = _spawn("echo", "hiya", 250 => 3)
  assert_process_exit_status pid, 127
rescue Errno::EBADF
  # this happens on darwin only. GNU does spawn and exits 127.
end

and it's actually the posix_spawn_file_actions_adddup2(fops, 3, 250) that's not erroring out as expected.

tmm1 commented 13 years ago

Isolated repro:

cat extconf.rb require 'mkmf' $CFLAGS << " -Wall -O0 -ggdb " create_makefile('posix_spawn_test')

cat test.c

ifndef _GNU_SOURCE

#define _GNU_SOURCE
#endif
#include <assert.h>
#include <errno.h>
#include <ruby.h>
#include <spawn.h>
#include <stdio.h>
void
Init_posix_spawn_test()
{
  int ret;
  posix_spawn_file_actions_t fops;
  pid_t pid;
  char *cargv[3] = {"echo", "hiya", NULL};

  posix_spawn_file_actions_init(&fops);
  posix_spawn_file_actions_adddup2(&fops, 3, 250);
  ret = posix_spawnp(&pid, cargv[0], &fops, NULL, cargv, NULL);
  printf("ret: %d\n", ret);
}

ruby -v && ruby extconf.rb && make && ruby -e' require "posix_spawn_test" ' ruby 1.8.7 (2010-12-23 patchlevel 330) [i686-darwin10.5.0] creating Makefile cc -dynamic -bundle -undefined suppress -flat_namespace -o posix_spawn_test.bundle test.o -L. -lruby -ldl -lobjc ret: 9

ruby -v && ruby extconf.rb && make && ruby -e' require "posix_spawn_test" ' rubinius 1.2.4dev (1.8.7 18066d4d yyyy-mm-dd JI) [x86_64-apple-darwin10.6.0] creating Makefile gcc -dynamic -bundle -undefined suppress -flat_namespace -o posix_spawn_test.bundle test.o -L. ret: 0 hiya

evanphx commented 13 years ago

I don't see why this should fail on MRI even. Isn't "posix_spawn_file_actions_adddup2" saying "take the kernel object at descriptor 3 and also reference it at descriptor 250" ?

tmm1 commented 13 years ago

You're right, the test is wrong. It's failing on rbx because there is actually no fd 3 created in the test, and 3 just happens to be valid during the test in MRI.

tmm1 commented 13 years ago

Fix invalid fd redirect test (closed by 152f32a03556eda67049337cd977ae69af817476)

tmm1 commented 13 years ago

@brynary I just pushed out a 0.3.4 gem that should work on rbx

brynary commented 13 years ago

You guys rock. Thanks.