In physics, we do contour integrals in a not so rigorous way most of the times. Now, I want to use a trick to compute $$\int_{-\infty}^{\infty}\frac{\sin(x)}{x}dx$$ using residue theory. I find:
$$\int_{-\infty}^{\infty}\frac{\sin(x)}{x}dx=2\pi$$which is clearly wrong since the correct value is $\pi$.
I don't know what I am doing wrong here but I think it might have to do with using the residue theorem in a clumsy way. Any help in finding the mistake will be much appreciated.
My solutions is the following(sorry if my notation(arguments) is too awkward(or not rigorous enough)):
$$\int_{-\infty}^{\infty}\frac{\sin(x)}{x}dx=Im\left[\int_{-\infty}^{\infty}\frac{e^{ix}}{x}dx\right]=Im\left[\lim_{ε\to0}\int_{-\infty}^{\infty}\frac{e^{ix}}{x-iε}dx\right]$$ which has a residue just above $x=0$ on the complex plane.
Now, consider the following integration paths:

So, I can write the above integral as:
$$Im\left[\lim_{ε\to0}\int_{-\infty}^{\infty}\frac{e^{ix}}{x-iε}dx\right]=Im\left[\lim_{ε\to0}\int_{C2}\frac{e^{ix}}{x-iε}dx\right]$$(of course $R\to \infty$)
Now, if we integrated the same integrand but the path was $C1$, it would give zero since the integrand tends to zero for large $Im[x]$ on the upper plane(this argument was used by a professor of our for a scattering problem in quantum mechanics).
So, we can now write:
$$Im\left[\lim_{ε\to0}\int_{C2}\frac{e^{ix}}{x-iε}dx\right]=Im\left[\lim_{ε\to0}\int_{C1+C2}\frac{e^{ix}}{x-iε}dx\right]$$which is an integral along a closed path that encloses the pole(residue) at $x=iε$. So, I can use the residue theorem to find that the integral is equal to: $$Im[\lim_{ε\to0}2\pi i Res(e^{i(iε)})]=2\pi $$ which is clearly off by a factor of 2.
So, which of the above arguments is wrong?
The problem is that in this case,
$$\int_{-\infty}^\infty\lim_{\varepsilon\rightarrow0}\frac{\sin x}{x-i\varepsilon}dx\ne\lim_{\varepsilon\rightarrow0}\int_{-\infty}^\infty\frac{\sin x}{x-i\varepsilon}dx.$$
The left-hand side is what you want, but the right-hand side is what you actually calculated. Really, what you found was the limit as $\varepsilon\rightarrow0^+$. If you had instead had $\varepsilon$ approach $0$ from below, you would have gotten $0$ as your answer. The limit on the left-hand side works out the same whether $\varepsilon$ approaches $0$ from the right or the left, so the fact that we get two different answers for the right-hand side immediately tells us something is wrong.
While this isn't rigorous, you'll note that the correct answer is halfway between the $2\pi$ you found for $\varepsilon\rightarrow0^+$ and the $0$ you get for $\varepsilon\rightarrow0^-$.