Solve $y' + y \cot x = 2 \cos x$ on $(0,\pi)$, and prove that there's a solution on $(-\infty,+\infty)$ Problem
This question concerns exercise #8 from section 8.5 of Calculus, Vol. I (Apostol):

Find all solutions of $y' + y \cot x = 2 \cos x$ on the interval $(0,\pi)$. Prove that exactly one of these is also a solution on $(-\infty,+\infty)$.

My specific doubt is about the portion "Prove that exactly one of these is also a solution on $(-\infty,+\infty)$", but I will give the full solution attempt for completeness.
Solution attempt
This equation has the form $y' + P(x)y + Q(x)$, where $P(x)$ and $Q(x)$ are continuous on the interval $(0,\pi)$. Assuming the initial condition that $y = b$ when $x = a$, the solution $y = f(x)$ is given by
$$f(x) = be^{-A(x)} + e^{-A(x)}\int_a^x Q(t) e^{A(t)} dt$$
where $A(x) = \int_a^x P(t) dt$.
To apply this formula, we choose $a = \pi/2$, so that all solutions will be expressed in terms of $b$. First, we compute:
$$A(x) = \int_{\pi/2}^x \cot tdt = \log (\sin x) - \log(\sin (\pi/2)) = \log(\sin x)$$
So, we get:
$$\begin{aligned}
    f(x) &= be^{-A(x)} + e^{-A(x)} \int_{\pi/2}^x 2(\cos t) e^{A(t)} dt \\
    &= be^{-\log(\sin x)} + 2e^{-\log(\sin x)} \int_{\pi/2}^x (\cos t) e^{\log(\sin t)} dt \\
    &= \dfrac{b}{\sin x} + \dfrac{2}{\sin x} \int_{\pi/2}^x \cos t \sin t dt \\
    &= \dfrac{b}{\sin x} + \dfrac{2}{\sin x} \int_1^{\sin x} u du & (u = \sin t,\ du = \cos t dt) \\
    &= \dfrac{b}{\sin x} + \dfrac{2}{\sin x} \dfrac{\sin^2 x - 1}{2} \\
    &= \dfrac{b}{\sin x} + \dfrac{\sin^2 x - 1}{\sin x} \\
    &= \dfrac{b - 1}{\sin x} + \sin x \\
    &= \sin x + \dfrac{C}{\sin x} & (C = b - 1)
\end{aligned}$$
The doubt arises in the part of proving that exactly one of these is also a solution on $(-\infty,+\infty)$.
If we let $C = 0$, we get the solution $f(x) = \sin x$. This function is defined for all $x$, so, at first, it appears that this is the answer. However, the original equation is not defined in $x=0$ to begin with, because $\cot x$ is not defined at $x = 0$. So, it seems that there shouldn't be a solution valid on the whole interval $(-\infty,+\infty)$.
What am I missing?

This is
$y'\sin x + y \cos x = 2 \cos x \sin x
$
or
$(y\sin x)' =\sin(2x)
$
so
$y\sin(x)
=-\frac12\cos(2x)+c
$
so
$y
=-\dfrac{\cos(2x)-c}{2\sin(x)}
=-\dfrac{1-2\sin^2(x)-c}{2\sin(x)}
=\sin(x)+\dfrac{c_1}{\sin(x)}
$.
For this to be defined
for all $x$,
we must have
$c_1 = 0$.
