Let $X_1, X_2, X_3,\dots$ be an i.i.d. sequence of random variables with finite mean. Write $S_n=X_1+X_2+\dots+X_n$.

Let $N$ be a non-negative integer-valued random variable with finite mean. $N$ may not be independent of the sequence $(X_i)$.

Is it necessarily the case that $S_N$ has finite mean?

Of course, it's true if $N$ is independent of the sequence $(X_i)$. Then $E(S_N)=E(N)E(X_1)$. It's still true if $N$ is a stopping time for the sequence $(X_i)$.

It's also true if the $X_i$ have finite variance. Then for any $c>E(X_i)$, the quantity $R_c=\sup(S_n-cn)$ has finite mean, and $E(S_N)\leq cE(N)+E(R_c)$.