In the lecture of E. Fradkin on quantum field theory, an example of Matsubara sum is performed using contour integration (see eq. 5.214 in the lecture). It reads $$ \sum_{n=-\infty}^{\infty} \frac{e^{in\tau}}{n^2+x^2} = \oint_{C_{+}\cup C_{-}} \frac{dz}{2\pi i} \frac{e^{iz\tau}}{z^2+x^2} \pi\cot(\pi z)\quad(\tau, x>0), $$ where $C_{\pm}$ denotes the lines $z\pm i\epsilon$ followed counter clockwise (see this figure). I see that above equation can be deduced applying residue theorem to the finite box, obtained by truncating $C_{+}\cup C_{-}$, and taking a limit.
To evaluate the right hand side, the author deforms the contour into $C^{+}\cup C^{-}$ and calculate instead residues at $z=\pm ix$. I am curious about the mathematical justification of this process.
To me, equating $\oint_{C_{-}}(\text{integrand})$ with residue at $-ix$ seems illegitimate since $e^{iz\tau}$ blows up as $z\rightarrow -i\infty$. I don't get what 'deforming $C_{-}$ to $C^{-}$' even means.
One approach that I tried is the change of variable $z\rightarrow 1/z$, which amounts to passing to the other coordinate chart of Riemann sphere. It goes like $$ (RHS)=\oint_{\Gamma} \frac{dz}{2\pi i} \frac{e^{i\tau/z}}{1+z^2x^2} \pi\cot(\pi/z), $$ where $\Gamma$ is the image of $C_{+}\cup C_{-}$ followed counter clockwise. The problem here is twofold; first, $\Gamma$ passes through the essential singularity at $z=0$. Second, if $C_{+}\cup C_{-}$ is taken to be the limit of boxes $B_n$ and $\Gamma$ the limit of their images $B'_n$, each contour $B'_n$ encircles an infinite subset of the poles $\{\pm 1/n: n\in\mathbb{Z}\}$. I have no idea if I can apply the residue theorem and take a limit in this case.
edit
Following Svyatoslav's suggestion, I obtained (for $0<\tau<2\pi$) $$ \sum_{n=-\infty}^{\infty} \frac{e^{in\tau}}{n^2+x^2} = \oint_{C_{+}\cup C_{-}} \frac{dz}{2\pi i} \frac{e^{iz\tau}}{z^2+x^2} \frac{\pi e^{-i\pi z}}{\sin\pi z} = \frac{\pi}{x} \frac{\cosh(\pi-\tau)x}{\sinh(\pi x)} \\ = \frac{\pi}{x} \left[ \cosh(\tau x) \coth(\pi x) - \sinh(\tau x) \right]. $$ However, it is claimed in (5.215) of the lecture that $$ \sum_{n=-\infty}^{\infty} \frac{e^{in\tau}}{n^2+x^2} \approx \frac{\pi}{2x}\coth(\pi x) e^{-|\tau|x} \quad \text{for small } \tau. $$ Did the author make a mistake?
This is a duplicate of what I wrote on Physics Stack exchange. I hope this is OK because there is a separate readership here.
You can also derive @Svyatoslav's correct expression by Poisson Summation: $$ \frac 1{2\pi} \sum_{n=-\infty}^\infty \frac{e^{in\tau}}{n^2+M^2}= \sum_{n=-\infty}^\infty \frac 1{2|M |} e^{-|M||\tau+2\pi n|}, \quad \hbox{(Poisson Summation)}\\ = \frac 1 {2M} \frac{\cosh(\pi -\tau)M}{\sinh \pi M}, \quad 0<\tau<2\pi,\nonumber $$ The first line come from applying Poisson summation to the zero temperature expression
$$ \int_{-\infty}^{\infty} \frac{dk}{2\pi}\frac{e^{ik\tau}} {k^2+M^2}=\frac 1 {2|M|}e^{-|\tau||M|} $$ and has the physical interpretation as the method-of-images sum over the $n$-fold winding of the particle trajectory around the periodic imaginary time direction. The passage from the first to second lines is just summing the two geometric series from $n=0$ to $ \infty$ and $n=-\infty$ to $-1$.