# FindRoot with NIntegrate: either recursion depth exceeded or numerical integration converging too slowly

Trying to numerically solve an equation involving an integral, either the error Recursion depth exceeded appears (when AccuracyGoal->10 or smaller) or the error Numerical integration converging too slowly appears. In the MWE below, the functions involved are smooth, bounded and the solution for the equation is 1 (as confirmed by Plot[{hdif[z], 0}, {z, smin, 2}]), so there should not be difficulty numerically integrating or solving.

How to find a solution to similar equations which cannot be solved by hand analytically?

MWE

Clear[smin, smax, h, hdif]
smin = -1;
h[z_] := Exp[-z/2]
hdif[zmax_?NumericQ] :=
NIntegrate[(Exp[z] - 1)*h[z], {z, smin, zmax}, AccuracyGoal -> 5]
smax = FindRoot[{hdif[smax] == 0}, {smax, 0, smin, Max[-smin, 1000]}]


Other solutions recommend increasing AccuracyGoal or WorkingPrecision (both of which I tried), cancelling periodic oscillations, integrating piecewise around points where the derivative is discontinuous (these do not apply to the function in question). Replacing NIntegrate with Integrate works for h[z_] := Exp[-z/2], but not for functions without a closed form integral.

You could use NDSolveValue for something like this:

smin = -1;
h[z_] := Exp[-z/2]
Last @ Reap[
NDSolveValue[
{
int'[z] == (Exp[z] - 1) h[z], int[smin] == 0,
WhenEvent[int[z]==0, {"StopIntegration", Sow[z, "zmax"]}]
},
int,
{z, smin, Infinity}
],
_,
#1 -> First@#2&
]


{"zmax" -> 1.}