NASA hates dealing with sex. It’s bad for business. (Budgets get approved through Congress and you’ll have to answer some very uncomfortable questions, publicly, asked sharply by a likely fat, likely old, likely conservative, likely male member of Congress about why you thought getting laid in zero g was a useful expenditure of taxpayer funding. Pass on that experience.) But a number of people, myself included, have thought about it and so there are a few different solution sets. The one that NASA prefers is to just select flight crews that are in control of themselves and/or no longer have this problem. “Astronaut” is normally a second career. The average age for an astronaut on their first flight is 44. The sex drive tends to decline somewhat as we age, so it is less of an issue then. This is, sometimes mockingly, called the Right Stuff approach. It will not work.

Some anecdotal evidence suggests that the underlying mechanics of sex don’t really work anyway. You’d be pushing rope.

Some have suggested having single sex crews. This doesn’t work in prisons, it won’t work in long-haul spaceflight.

Some say have assigned pairs that you can chuckle off with when the mood strikes. Except this almost never works. You think it’s awkward when you break up with a co-worker? This is like banging your roommate, except for the next three years, this is all there is. Not a great solution.

Probably the best solution is a kind of a sexual Mayflower Compact in which everyone can have sex with anyone. But then the problem there is you’ll need contraceptives and morning after pills. Which again, goes back to the fat ugly lawmaker asking why the taxpayer is funding floating hypersonic astronaut orgies.

It’s one of the trickier problems in human spaceflight, actually, because it’s so poorly understood.

Another idea could be for NASA to send astronauts (on a long-haul mission) with a bunch of sex toys. But once again having taxpayers pay to send sex toys to space may not go over too well.