Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Writing a mod_fcgid responder in Rust. |
|
Author |
|
animats
Joined: 16 Aug 2025 Posts: 3 Location: Silicon Valley, CA
|
Posted: Sat 16 Aug '25 7:52 Post subject: Writing a mod_fcgid responder in Rust. |
|
|
I'm trying to run a mod_fcgid responder written in Rust on Dreamhost shared hosting. I've done this successfully from Go, but now I'm trying to do it from Rust. Had to write an entire responder library, because all the existing ones are standalone or run under ngnix.
If I can get far enough that a simple test program will return error messages, I can do this. But right now, I can't get that far. I'm stuck at:
500 Internal Server Error error.
The Apache logs say:
Code: |
error
[pid 964859] util_script.c(497): End of script output before headers: vehiclelogserver.fcgi
warning
[pid 964859] fcgid_proc_unix.c(627): (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
|
I'm doing something basic wrong, obviously.
Version info:
Code: | /usr/sbin/apache2 -v
Server version: Apache/2.4.52 (Ubuntu)
Server built: 2025-08-11T12:10:10 |
My own code:
https://github.com/John-Nagle/maptools/tree/main/server
See example "echo", which I upload as "echo.fcgi"
This is just the beginnings of a responder. Doesn't do anything useful yet.
The headers I'm sending (or at least think I am) are the usual 8-byte FCGI header followed by content, per the spec at https://www.mit.edu/~yandros/doc/specs/fcgi-spec.html
If I run the program from a command line on the server, my program generates
Code: | ./echo.fcgi
ffsafsfsdf
�bStatus: 500 FCGI responder error: Invalid FCGI record type: 102
Content-Type: text; charset=utf-8��� |
(That's printing bytes as text, so the binary headers are garbage characters.)
So it's sending something reasonable, although "id" may be wrong if the error message
happens before the input records have been parsed.
Obvious things checked:
- Executable "echo.fcgi" is executable.
- I can't see the Dreamhost config files, but .htaccess is exactly the same as it is for the site that runs a Go program.
Aux questions:
- Is there any way I can put a log entry into the Apache log from this program? Writing to stderr seems to go nowhere.
Thanks. |
|
Back to top |
|
animats
Joined: 16 Aug 2025 Posts: 3 Location: Silicon Valley, CA
|
Posted: Sat 16 Aug '25 21:50 Post subject: More info - stdin raw mode problem? |
|
|
Added logging and stripped down the program for a test.
What's wrong is that I get an OS error 22 (EINVAL) reading from stdin.
Here's the Rust code:
Code: | let inio = std::io::stdin();
let mut instream = inio.lock(); // Lock the stdin for reading.
let mut header_bytes:[u8;8] = Default::default();
use std::io::Read;
let stat = instream.read_exact(&mut header_bytes);
log::debug!("Stat: {:?} Bytes: {:?}", stat, header_bytes); |
That returns
Code: | 19:14:55 [DEBUG] (1) echo: Stat: Err(Os { code: 22, kind: InvalidInput, message: "Invalid argument" }) Bytes: [0, 0, 0, 0, 0, 0, 0, 0]
|
This seems to be some kind of incompatibility between mod_fcgid's pipes/sockets and what Rust does with stdin. |
|
Back to top |
|
animats
Joined: 16 Aug 2025 Posts: 3 Location: Silicon Valley, CA
|
|
Back to top |
|
James Blond Moderator

Joined: 19 Jan 2006 Posts: 7431 Location: EU, Germany, Next to Hamburg
|
|
Back to top |
|
|
|
|
|
|