A dodgy contour integration method giving the correct result Consider the following integral
$$I = \int_{-\infty}^\infty \frac{x}{\sinh x}dx$$
Using contour integration with some rectangular contour, it is not too hard to show that the integral evaluates to $\pi^2/2$. However, as shown in this reply, it is apparently possible to get the correct answer using a semi-circular contour in the upper half-plane, despite the fact that the integral over the contour technically doesn't vanish. As the radius of the semi-circular contour tends to infinity, there are an infinite number of poles contained within the contour with residues $i\pi n$ and $-i\pi n$ for $n$ is even and odd respectively. By assuming that the integral on the semi-circular contour vanishes, the residue theorem yields $$I = 2\pi i \sum_{n=0}^\infty (-1)^n (i\pi n) = -2\pi^2\sum_{n=0}^\infty (-1)^n n = \frac{\pi^2}{2}$$
if we consider that the last series goes to $-1/4$.
Now, despite the fact that the final answer is correct, the method used seems heretical for three reasons:

*

*Assuming the integral on the semi-circular contour vanishes when it clearly doesn't on the imaginary axis.


*Considering an infinite number of poles within the contour (although it's not too hard to accept that the residue theorem can also be used if the number of poles within a contour is countably infinite).


*Assuming that the last traditionally divergent series actually converges in this context.
Why does this nevertheless yield the correct result? It's a safe assumption that it is not coincidental, since the entire family of integrals
$$I(n) = \int_{-\infty}^\infty \left(\frac{x}{\sinh x}\right)^n dx$$
can seemingly be evaluated correctly by using this method, with the only difference being the type of divergent series at the end.
 A: We wish to evaluate the integral $\int_{-\infty}^\infty \frac{x}{\sinh(x)}\,dx$ using contour integration with a contour that is closed in the upper-half plane by a semi-circular arc.
One way to proceed is to close the upper-half plane with a semi-circular contour of radius $(N+1/2)\pi$.  Then, we can write
$$\begin{align}
\oint_{C}\frac{z}{\sinh(z)}\,dz&=\int_{-(N+1/2)\pi}^{(N+1/2)\pi}\frac{x}{\sinh(x)}\\\\
&+\int_0^\pi \frac{(N+1/2)\pi e^{i\phi}}{\sinh((N+1/2)\pi e^{i\phi})}\,i(N+1/2)\pi e^{i\phi}\,d\phi\\\\
&=-2\pi^2  \sum_{n=1}^N (-1)^n n\\\\
&=\frac{\pi^2}2 - \frac{\pi^2}{2}(-1)^N(2N+1)
\end{align}$$
Now, it shouldn't be difficult to show that
$$\lim_{N\to\infty}\left(\int_0^\pi \frac{i(N+1/2)^2\pi^2 e^{i2\phi}}{\sinh((N+1/2)\pi e^{i\phi})}\,d\phi+\pi^2(-1)^N(N+1/2)\right)=0$$
A: Considering that zeta-regularization applied to $\sum_{n=1}^{\infty} (-1)^n n$ yields the correct answer, we may attempt to regularize the integral first and then appeal to the principle of analytic continuation.
In this pursuit, it doesn't really matter if we use a semicircular contour or rectangular contour. (Indeed, continuously deforming a contour while avoiding the singularities does not change the value of a contour integral.) What matters most is the fact that the sum of residues diverges as the contour encompasses larger region.  So, we will stick to rectangular contours.
First, we introduce a parameter $s$ and note that
\begin{align*}
\int_{-\infty}^{\infty} \frac{x}{\sinh x} \, \mathrm{d}x
&= 2 \int_{0}^{\infty} \frac{x}{\sinh x} \, \mathrm{d}x \\
&= 2 \lim_{s \to 1} \int_{0}^{\infty} \frac{x^s}{\sinh x} \, \mathrm{d}x
= 2 \lim_{s \to 1} J(s),
\end{align*}
where $J(s)$ is defined for all $s \in \mathbb{C} \setminus \mathbb{Z}$ by
$$ J(s) = \frac{1}{1 - e^{2\pi i s}} \int_{\mathcal{C}} \frac{z^s}{\sinh z} \, \mathrm{d}z $$
and $\mathcal{C}$ is the clockwise-oriented Hankel contour, composed of a small circle about $0$ and two half-infinite lines "just right" above and below the positive $x$-line:

Now replace each of the two half-infinite lines by a line segment of length $R$ , and denote the resulting "truncated" Hankel contour by $\mathcal{C}_R$.

Then we may write $J(s)$ as
$$ J(s) = \lim_{R\to\infty} J_R(s),
\qquad\text{where}\qquad
J_R(s) := \frac{1}{1 - e^{2\pi i s}} \int_{\mathcal{C}_R} \frac{z^s}{\sinh z} \, \mathrm{d}z. $$
From this point on, we assume $-2 < \operatorname{Re}(s) < -1$ and $R = (N+\frac{1}{2})\pi$ for $N = 0, 1, 2, \ldots$. Then, as we continuously inflate the contour $\mathcal{C}_R$ to a clockwise-oriented square $\mathcal{S}_R$ with vertices $\pm R \pm iR$, the deformation will sweep poles of the integrand at $z = \pm \pi i, \pm 2\pi i, \ldots, \pm N\pi i$. Hence,
\begin{align*}
J_R(s)
&= \frac{2\pi i}{1 - e^{2\pi i s}} \biggl[ \sum_{n = \pm 1, \ldots, \pm N} \,\underset{z=n\pi i}{\mathrm{Res}}\, \frac{z^s}{\sinh z} + \frac{1}{2\pi i} \int_{\mathcal{S}_R} \frac{z^s}{\sinh z} \, \mathrm{d}z\biggr] \\
&= \frac{2\pi i}{1 - e^{2\pi i s}} \biggl[ \pi^s (e^{i\pi s/2} + e^{3i\pi s/2}) \sum_{n = 1}^{N} (-1)^n n^s + \mathcal{O}(N^{1+\operatorname{Re}(s)}) \biggr] \\
&= \frac{\pi^{s+1}}{\sin(\pi s/2)} \sum_{n = 1}^{N} (-1)^{n-1} n^s + \mathcal{O}(N^{1+\operatorname{Re}(s)}).
\end{align*}
So, as $N \to \infty$, it follows that
\begin{align*}
J(s)
&= \frac{\pi^{s+1}}{\sin(\pi s/2)} \sum_{n = 1}^{\infty} (-1)^{n-1} n^s \\
&= \frac{\pi^{s+1}}{\sin(\pi s/2)} (1 - 2^{1+s}) \zeta(-s).
\end{align*}
However, since $\mathbb{C}\setminus\mathbb{Z}$ is connected and both sides of the above equality are holomorphic functions on $\mathbb{C}\setminus\mathbb{Z}$ that agree on a non-empty open subset, they must agree on all of $\mathbb{C}\setminus\mathbb{Z}$ by the principle of analytic continuation. This justifies OP's heuristics, and in particular,
$$ I = 2 \lim_{s \to 1} J(s)
= \frac{2\pi^2}{\sin(\pi/2)} (1 - 2^{2}) \zeta(-1)
= \frac{\pi^2}{2}. $$

Addendum. The above argument also shows that, for any $\operatorname{Re}(s) > 0$,
$$ \int_{0}^{\infty} \frac{x^s}{\sinh x} \, \mathrm{d}x
= \frac{\pi^{s+1}}{\sin(\pi s/2)} (1 - 2^{1+s}) \zeta(-s) $$
On the other hand, the left-hand side can be easily computed as:
\begin{align*}
\int_{0}^{\infty} \frac{x^s}{\sinh x} \, \mathrm{d}x
&= 2 \sum_{n=0}^{\infty} \int_{0}^{\infty} x^s e^{-(2n+1)x} \, \mathrm{d}x \\
&= 2 \sum_{n=0}^{\infty} \frac{\Gamma(s+1)}{(2n+1)^{s+1}} \\
&= 2 \Gamma(s+1) (1 - 2^{-s-1}) \zeta(s+1).
\end{align*}
Comparing both sides, we get
$$ \zeta(-s)
= - \frac{2 \Gamma(s+1)}{(2\pi)^{s+1}} \zeta(s+1) \sin(\pi s/2) 
$$
and this is just the Riemann's functional equation for $\zeta(\cdot)$ in disguise.
A: Let $N$ be a positive integer.
To make the approach rigorous, we can integrate  the modified function $$f(z) = \frac{z e^{iaz}}{\sinh z}, \quad  a >0,  $$ around the same contour, that is,  a contour consisting of the real axis from $-(N+1/2)$ to $(N+1/2)$ and the semicircle above it.
The integral will vanish along the semicircle as $N \to \infty$ through the positive integers because the magnitude of $f(z)$ decays exponentially to zero along along the entire semicircle.
Therefore,  we have $$\int_{-\infty}^{\infty} \frac{x e^{iax}}{\sinh x} \, \mathrm dx = 2 \pi i \sum_{n=1}^{\infty}\operatorname{Res}[f(z), i n \pi] = 2 \pi^{2}  \sum_{n=1}^{\infty}(-1)^{n-1}n e^{-a n \pi} = 2 \pi^2 \, \frac{e^{a \pi}}{(1+e^{a \pi})^{2}}. $$
But since  $x e^{iax} \operatorname{csch}(x)$ is dominated on $(-\infty, \infty)$ by the integrable function $x \operatorname{csch}(x)$, we have $$\begin{align} \lim_{a \to 0^{+}} \int_{-\infty}^{\infty}  \frac{x e^{iax}}{\sinh x} \, \mathrm dx &= \int_{-\infty}^{\infty}  \frac{x}{\sinh x} \, \mathrm dx \\  &=  2 \pi^{2}\lim_{a \to 0^{+} } \frac{e^{\pi a}}{(1+e^{\pi a})^{2}} \\   &= \frac{\pi^{2}}{2}. \end{align}$$
