Residue theorem: how to choose upper or lower half if only one pole exists NOTE: bad example, but the question at the end still holds $\to$ solution: don't forget about the semi-circular paths!
Let's consider the following integral:
$$ \int_{-\infty}^\infty \mathrm dx \frac{1}{x-\mathrm i} $$
This integrand has a pole at $x=\mathrm i$. When I close the contour in the upper complex plane, I pick up the residue 1, which leads to the result
$$ \int_{-\infty}^\infty \mathrm dx \frac{1}{x-\mathrm i} = 2\pi \mathrm i \sum \text{contour orientation}\times\text{residues} = 2\mathrm i\pi $$
But when I close the contour in the lower plane, there is no residue, so the result is zero. How do I make sense of these two seemingly different results?
 A: The integral on the semicircle of radius $R$ does not go to zero as $R\to\infty,$ so this technique won’t work.
Indeed, this integral does not converge. Multiply the numerator and denominator by $x+i$ and you get: $$\frac{1}{x-i}=\frac{x+i}{x^2+1}$$ and the indefinite integral is:
$$\int\frac{x+i}{x^2+1}dx=\frac{1}2\ln(x^2+1)+i\arctan x +C.$$
So there is a value to $$\lim_{R\to\infty}\int_{-R}^R \frac1{x-i}dx=i\pi.$$
But that is only a principle value for the integral. That’s because:
$$\int_0^{\infty}\frac1{x-i}dx$$ diverges.
A: Because of the chosen tags I would assume that you are interested in the principal value of this integral since otherwise it cannot be evaluated in view of its divergence. The residue theorem is the correct tool for computing the Cauchy principal value.
The reason for your seemingly different results for the upper and lower half-plane contours is the false assumption that the value of the integral along the semicircular path is $0$. However it is simple to show using the path along arc of the circle centered at $z=i $ that the integral value is equal (in the limit $R\to\infty $) to $\pi i $ and $-\pi i $ for the upper and lower half-plane, respectively.
Subtracting the value from the residue of the poles surrounded by the respective contour one obtains  the principal value $\pi i $ for the integral in question in both cases. No contradiction arises.
