Space. The final frontier. I agree it has to have already happened. Thanks for the links. Pieterjoke came up with the obvious solution. For some reason I never even thought of using a condom to masturbate. All I pictured is a guy who's a heavy shooter shooting over his head and then trying to mop up the drops before anyone catches him.
When I think of sex in outer space I don't think so much of people having sex, because of all the complications, but I do think of how most guys can't go more than a few days or weeks without becoming uncomfortable. It will probably mostly be guys anyway. Any women on the missions can't be expected to be a sperm repository for a spaceship full of guys. It does seem like a natural environment for a buddy to help a buddy, but we know how complicated that can get. But it would be kind of stupid to be all clandestine about it. I have a housemate situation and he and I masturbate whenever and wherever we want to. Being used to it now, it would be difficult to have it any other way.
I've been in a same sex environment for months, Army training--and I can tell you people are pretty sneaky about it. The whole time I was in basic training, we only caught one guy jerking off in the bathroom stall. Somebody heard him and kicked the door open. But I used to have to clean the urinals in the morning and they were always full of sperm. So I know it will come out, but under those circumstances, it can be done quickly.
Maybe Pablo has it right. It will be some kind of a masturbation machine, because they already have those for guys with erectile dysfunction. It's like a penis pump and a milking machine put together. A guy I met through restore-list said he and his [long suffering] wife both loved his. It is called something like a Venus II or Venus 2000 or something. That's another mission altogether.