简体   繁体   中英

Mono hangs when called from a CGI script

I have a program written in C# which I need to call from a CGI script.

When I call the program from either a python or bash CGI script:

#!/bin/bash
echo Content-type: text/plain
echo
echo    
/home/<user>/.mono/bin/mono HelloWorld.exe

or

#!/usr/bin/python

import subprocess

print 'Content-type: text/plain\n\n'
p=subprocess.Popen(['/home/<user>/.mono/bin/mono','HelloWorld.exe'], stdout=subprocess.PIPE)
print p.stdout.read().strip('\r\n')

the process hangs and the browser waits indefinitely for a response. As you will have noticed I have mono "installed" in my home directory as I don't have root privileges. It was compiled on the server and the executable is just sitting in that directory, but it seems to work fine for everything else.

What makes the problem confusing is:

  • The problem doesn't occur if I call the command or indeed the cgi script myself eg. from an SSH session.
  • The problem seems to occur after the program has run: if I pipe the results to a file the results appear in the file file, mono just seems to hang after it's finished.
  • The problem doesn't occur on my mac laptop with the same cgi script and .exe but with mono properly installed.
  • The problem doesn't occur if the script just calls mono eg. ( subprocess.Popen(['/home/<user>/.mono/bin/mono'], stdout=subprocess.PIPE) ) - mono just prints the standard "you've given me nothing to do" message and exits normally.
  • The problem occurs with any .exe whether it is just hello world or making some relatively complex calculations, which is what my actual program does.

I've tried setting MONO_SHARED_DIR to a directory that is world writable as I originally thought this was the same problem as that seen with fake-root see the Mono FAQ page .

gdb gives the following output:

Loaded symbols for /lib/libpthread.so.0
Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from /lib/libnss_compat.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/libnss_compat.so.2
Reading symbols from /lib/libnsl.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/libnsl.so.1
Reading symbols from /lib/libnss_nis.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/libnss_nis.so.2
Reading symbols from /lib/libnss_files.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/libnss_files.so.2
0x00007f85d7680b50 in sem_wait () from /lib/libpthread.so.0

I've googled the last line and sem_wait but I can't find anything relevant as this seems to be a common problem.

Any help on this problem would be very much appreciated, I really don't want to rewrite my whole program in C++ from C#.

Version information:

  • OS: Ubuntu 10.04.3 LTS
  • Mono: Mono JIT compiler version 2.10.2 (tarball Sat Jun 18 15:11:20 BST 2011)
  • Apache: Apache/2.2.14 (Ubuntu)

The answer probably isn't interesting to most people, but for completeness I should provide it.

Retrosnub who run the server I was using have a separate web server and ssh server. I had obviously compiled mono on the ssh server, but when I tried calling it from a CGI script it was being executed by the web server. The web server has a different architecture (32bit not 64bit) which caused all the problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM