6. When $0<\theta<\frac{\pi}{2}$, the maximum value of the function $y=\left(\frac{1}{\sin \theta}-1\right)\left(\frac{1}{\cos \theta}-1\right)$ is
A. $\sqrt{2}-1$
B. $2-\sqrt{2}$
C. $2 \sqrt{3}-3$
D. $3-2 \sqrt{2}$
6. D $y=\frac{1}{\sin \theta \cos \theta}+1-\left(\frac{1}{\sin \theta}+\frac{1}{\cos \theta}\right)=\frac{1}{\sin \theta \cos \theta}+1-\frac{\sin \theta+\cos \theta}{\sin \theta \cos \theta}$. Let $t=\sin \theta+\cos \theta$ then $t \in(1, \sqrt{2}], \quad \sin \theta \cos \theta=\frac{t^{2}-1}{2} \quad y=\frac{2-2 t}{t^{2}-1}+1=\frac{-2}{t+1}+1 \leqslant \frac{-2}{\sqrt{2}+1}+1=3-2 \sqrt{2}$